Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在数据帧中迭代行时如何避免TypeError?_Python_Pandas - Fatal编程技术网

Python 在数据帧中迭代行时如何避免TypeError?

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

我的情况: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='|', 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)
,我也有同样的错误。