[Python] Difference between Index and RangeIndex in pandas

Discussão em 'Python' iniciado por Stack, Maio 30, 2025.

  1. Stack

    Stack Membro Participativo

    I have two pandas dataframe df1 and df2, which look the same, but have a difference in the index, if you print both, it looks like:

    print(df1)
    Kalenderjahr/Monat Kostenstelle Kontonummer Wert timepoint
    0 202410 A 0054010000 32641.10 2024-10-01
    184 202303 B 0054010008 238.14 2023-03-01


    print(df2)
    Kalenderjahr/Monat Kostenstelle Kontonummer Wert timepoint
    0 202410 A 0054010000 32641.10 2024-10-01
    184 202303 B 0054010008 238.14 2023-03-01


    and if I Print the index:

    print(df1.index)
    dtype: object
    RangeIndex(start=0, stop=156, step=1)

    print(df2.index)
    dtype:eek:bject


    How can I adjust df1 the same way, that it has the same index structure as df2? what is the difference between the two?

    The index of df1 'RangeIndex'. The index of df2 is a 'Int64Index'.

    Continue reading...

Compartilhe esta Página