如何在dataframe中插入增量索引,或如何重新分配/重新对齐现有索引项。
目前,我的数据格式是: df.head(4)
------------------
| |amount|
------------------
|id | |
-----------------
|cb782ea3 | 3750|
------------------
|bhek8s9 | 900|
------------------
|hdci39w | 3450|我需要的要么是:
------------------
|id |amount|
-----------------
|cb782ea3 | 3750|
------------------
|bhek8s9 | 900|
------------------
|hdci39w | 3450|或
-----------------------
| |id |amount|
-----------------------
|0 |cb782ea3 | 3750|
----------------------
|1 |bhek8s9 | 900|
-----------------------
|2 |hdci39w | 3450|发布于 2014-11-01 13:37:19
您可以用以下方式重置索引:
df.reset_index(inplace=True)这也将重新分配Id。
https://stackoverflow.com/questions/26689809
复制相似问题