我需要用另一个值替换熊猫 df 每一行中的特定值。我的数据如下所示:
time log
1 whats the weather look like today
2 what is the weather look like today
3 whats for lunch
4 what’s for lunch
我需要替换whats
是what is
和what‚Äôs
也是what is
。所需的输出:
time log
1 what is the weather look like today
2 what is the weather look like today
3 what is for lunch
4 what is for lunch
我试过了:
new_df = df.log.str.replace("^whats", "what is").str.replace("^what’s", "what is")
这解决了,whats
但不是其他情况,结果不是熊猫 df,我需要它是熊猫 df。