简体   繁体   English

如何在 python 中的 Dataframe 中创建新的自动增量列

[英]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.

相关问题 如何在 python 中的 dataframe 中动态创建新列 - How to create new column dynamically in dataframe in python Python Spark - 如何创建一个新列,在数据帧上对现有列进行切片? - Python Spark - How to create a new column slicing an existing column on the dataframe? 如何遍历数据框,创建新列并在python中为其添加值 - How to loop through a dataframe, create a new column and append values to it in python 如何比较 Python 数据框中的子字符串以创建新列? - How do you compare substrings in a Python dataframe to create a new column? 如何使用 for 循环在 python dataframe 中创建具有多个值的新列? - How to create a new column with multiple values in python dataframe using for loop? 如何在 DataFrame 中删除多列中的内容并在 Python 中创建新列 - How to remove contents in multiple columns and create a new column in a DataFrame In Python 如何根据python中现有列中的条件创建新列? - How to create a new column based on conditions in the existing columns in a dataframe in python? Python Dataframe如何根据条件创建新的列值 - Python Dataframe how to create a new column values based on a condition 如何通过引用其他两列在 Python Dataframe 中创建新列? - How to create a new column in Python Dataframe by referencing two other columns? 移位数据并创建新列-Python数据框 - Shift Data and create new column - python dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM