[Python] df.to_csv() giving *** TypeError: slice indices must be integers or None or have an...

Discussão em 'Python' iniciado por Stack, Março 12, 2025.

  1. Stack

    Stack Membro Participativo

    I get the above error when i try df2.to_csv('abc.csv').

    More details:

    (Pdb) type(df2)
    <class 'pandas.core.frame.DataFrame'>
    (Pdb) df2
    0x01 0x03 0x07 0x0f 0x1f 0x3f 0x7f
    0 2 NaN NaN NaN NaN NaN NaN
    1 10 2 5 2 4 4 NaN
    2 26 4 17 16 25 10 1
    3 12 11 25 13 31 21 7
    4 10 37 24 22 18 37 33
    5 10 39 23 21 13 15 27
    6 22 7 5 11 5 3 23
    7 8 NaN NaN 4 3 3 6
    8 NaN NaN 1 11 1 7 3

    [9 rows x 7 columns]
    (Pdb) df2.to_csv('abc.csv')
    *** TypeError: slice indices must be integers or None or have an __index__ method
    (Pdb)


    I am not slicing anything ... so the error makes no sense.

    Continue reading...

Compartilhe esta Página