[英]Assign new string in the beginning of a text in a specific row and column pandas
我已经尝试了一段时间了,是否有一种可能的方法可以在特定行和列的文本开头附加一个新单词。 举个例子;
Body
.
.
.
John, where are you?
期望的输出:
Body
.
.
.
Hello John, where are you?
我试过:
rowIndex = df.index[109]
df.loc[rowIndex , 'Body'].append.str[:0].('Hello')
但是,它没有用,感谢您对此提出的建议,并提前感谢您!
使用+
来添加新字符串:
df.loc[rowIndex , 'Body'] = 'Hello ' + df.loc[rowIndex , 'Body']
样品:
df = pd.DataFrame({'Body':['','','John, where are you?']}, index=[100,200,300])
print (df)
Body
100
200
300 John, where are you?
rowIndex = df.index[2]
df.loc[rowIndex , 'Body'] = 'Hello ' + df.loc[rowIndex , 'Body']
print (df)
Body
100
200
300 Hello John, where are you?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.