a.csv:
1.发现pandas.DataFrame.replace只能替换整个值,而非一部分值
import pandas as pd
data = pd.read_csv('a.csv')
data['text'].replace('大', '小', inplace=True) # 不起作用,无法局部替换
data['text'].replace('赵某人是大狗狗?', '赵某人是小狗狗?', inplace=True)
data.to_csv('a.csv',index=False, header=['', 'text'])
解决方法:利用python字符串的replace方法
import pandas as pd
data = pd.read_csv('a.csv')
data['text'] = data['text'].str.replace(r'大','小')
data.to_csv('a.csv',index=False, header=['', 'text'])
参考博客:https://blog.csdn.net/weixin_30945845/article/details/112960922