[英]How to Create new Autoincrement Column in to Dataframe in python
I have a basic question in python我在 python 有一个基本问题
How to create Index Column with Auto Increment with 1 which is similar to X=X+1如何使用 1 创建具有自动增量的索引列,类似于 X=X+1
Data['Index'] = Data['Index'] + 1 --> This line didn't worked for me
It's not entirely clear what you're trying to do.目前尚不清楚您要做什么。 If you want to have a new index auto-incrementing from 1:如果你想让一个新的索引从 1 开始自动递增:
df["new_index"] = df.index + 1
should work.应该管用。
I think the problem you may have had is calling your new column by the same name you are incrementing.我认为您可能遇到的问题是用您要递增的相同名称来调用您的新列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.