python - 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)
但是当我从输出值复制粘贴时,它可以工作,但是当我手动输入时它没有,似乎存在编码问题。知道如何解决吗?
解决方案
推荐阅读
- c++ - 在 C++ 中创建字符串时抛出奇怪的错误
- ios - 如何在没有 3rd 方库 iOS Swift 的情况下绘制饼图,获得的标记填充总标记中的一些颜色
- reactjs - 带有事件的 Swiperjs 反应
- php - Laravel 的内置 Auth 功能在使用带有前缀 url 的本地化时会导致错误
- python - 安装 anaconda 后,无法导入新的 pip 安装模块
- python - Python将不相等的数据帧与真/假文本进行比较以获取列输出
- python - 如何处理字符串列表,其中每个字符串也可能是逗号分隔的字符串列表?
- javascript - 奇怪的重新选择选择器行为
- jmeter - 在 JMeter 的 HTTP 采样器中遍历每一行并访问每一列
- javascript - 将基于 ES6 钩子的应用程序转换为基于类的组件