[英]If list of lists values are present in Pandas dataframe column replace them with values from another Pandas column
[英]Replace the # values present in a column in pandas dataframe with auto-incremental values by rows
场景是:VendorID 列在 pandas 数据帧的所有行中都包含“#”。 我一直在尝试将 VendorID 列中的“#”值替换为自动递增行号值。
我正在尝试 str.replace() 函数:
data['VendorID'].str.replace(r'[#]', replacing_value)
我想弄清楚我应该在上面的行中写什么来代替replace_value
目前它的显示如下:
VendorID
#
#
#
.
.
预期的:
VendorID
0
1
2
3
.
.
.
df['VendorID']= pd.Series(range(1,df.shape[0]+1)) #starts with 1
或者
df['VendorID']= pd.Series(range(0,df.shape[0])) #starts with 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.