【发布时间】:2021-05-14 00:53:01
【问题描述】:
我正在尝试将字典应用于包含字符串行的数据框列,例如:
0 [一些、文本等...
1 [其他,文字...
并使用了以下代码,该代码适用于单个字符串,但不适用于数据框:
dict = pd.read_csv(r'C:\Users\dictionary.csv', header=None, dtype={0: str}).set_index(0).squeeze().to_dict()
def dictionary(text):
for x in dict:
for y in text:
if dict[x][0] == y:
y == x[1]
text = ' '.join(dict.get(y, y) for y in text)
return
df['Processed'] = df['Processed'].apply(dictionary)
df['Processed']
产生以下错误
<ipython-input-75-decedde15a18> in dictionary(text)
5 def dictionary(text):
6 for x in dict:
----> 7 for y in text:
8 if dict[x][0] == y:
9 y == x[1]
TypeError: 'NoneType' object is not iterable
感谢任何关于我做错了什么的帮助/指导!谢谢
【问题讨论】:
标签: pandas dictionary normalization