我试图用从json文件读取的字典替换pandas列中的字符和单词
specialChars.json {'è':'e', ‘µ’:‘u’, 'a':'a', 'bar':'bat'}
with open('specialChars.json', 'r', encoding='utf-8') as handle:
specialChars = json.loads(handle.read())
df
col1
0 foo bar
1 fèe foo
desired result
col1
0 foo bat
1 fee foo
我试过了
df[col1].replace(specialChars, regex=True)
它似乎与读取json有关,因为如果我把它作为一个直接的字典放在代码中,它会工作吗
谢谢你的帮助
解决了。函数和字典同名
相关问题 更多 >
编程相关推荐