首页 > 解决方案 > Pandas Series.str.replace () 在我的情况下不起作用

问题描述

Series.str.replace()在 csv 文件中不起作用。我'property_location'在 DataFrame 中有列命名。我想替换列中的值:

loc_dict={
'Yeniyol':'Ismayilli',
}
df['property_location']=df['property_location'].replace(loc_dict)

当我检查列的字符串值时,我注意到

'Yeniyol'没有被替换,我没有收到任何错误消息:

df['property_location'].unique()

array(['Ağstafa', 'Yeniyol', 'Kürdǝmir'], dtype=object)

但是当我从输出值复制粘贴时,它可以工作,但是当我手动输入时它没有,似乎存在编码问题。知道如何解决吗?

标签: pythonpandas

解决方案


推荐阅读