Python 在数据帧中迭代行时如何避免TypeError?
我的情况:2个数据帧Python 在数据帧中迭代行时如何避免TypeError?,python,pandas,Python,Pandas,我的情况:2个数据帧IndicRef和prescripto。 我想使用wuzzyfuzzy将prescripto['label']中的每个单词与我的word数据库列IndicRef['Nom_medicament']匹配 我的代码: import csv import pandas as pd from fuzzywuzzy import fuzz from fuzzywuzzy import process IndicRef=pd.read_csv(path, sep='|', encodi
IndicRef
和prescripto
。
我想使用wuzzyfuzzy将prescripto['label']
中的每个单词与我的word数据库列IndicRef['Nom_medicament']
匹配
我的代码:
import csv
import pandas as pd
from fuzzywuzzy import fuzz
from fuzzywuzzy import process
IndicRef=pd.read_csv(path, sep='|', encoding='utf-8')
PrescriPresco=pd.read_csv(path,sep=',', encoding='utf-8')
print(IndicRef)
print(PrescriPresco)
for index, row in PrescriPresco.iterrows():
Correspondinglabel= process.extractOne(PrescriPresco['label'], IndicRef['Nom_medicament'], scorer=fuzz.token_sort_ratio)
print(Correspondinglabel)
我得到的错误是:
TypeError:expected string或bytes-like-object
数据中很可能有NaN元素。你应该把它们过滤掉beforehand@maxbachmann它不起作用。我尝试了IndicRef.replace(np.nan',regex=True,inplace=True)PrescriPresco.replace(np.nan',regex=True,inplace=True)
,我也有同样的错误。