Я объединил три кадра данных. Как я могу напечатать df.index в RangeIndex вместо Int64Index?
Мой вклад:
df = pd.concat([df1, df2, df3])
print(df.index)
Мой вывод:
Int64Index([ 0, 1, 2, 3, 4, 5, 6, 7, 8,
9,
...
73809, 73810, 73811, 73812, 73813, 73814, 73815, 73816, 73817,
73818],
dtype='int64', length=495673)
Желаемый результат:
RangeIndex(start=X, stop=X, step=X)






Вы можете использовать reset_index для получения желаемых индексов. Например:
df = pd.concat([df1,df2,df3])
df.index
Int64Index([0, 1, 2, 0, 1, 2, 0, 1, 2], dtype='int64')
После сброса индексов:
df.reset_index(inplace=True)
df.index
RangeIndex(start=0, stop=9, step=1)
Также хорошо использовать ключевое слово axis в функции concat.
вы можете использовать встроенную опцию ignore_index:
df = pd.concat([df1, df2, df3],ignore_index=True)
print(df.index)
Из документов:
ignore_index : boolean, default False If True, do not use the index values along the concatenation axis. The resulting axis will be labeled 0, …, n - 1. This is useful if you are concatenating objects where the concatenation axis does not have meaningful indexing information. Note the index values on the other axes are still respected in the join.