У меня есть файл данных, который выглядит следующим образом - ![enter image description here](https://i.stack.imgur.com/InQxx.png)
И у меня есть другой файл данных, который имеет все правильные названия стран.![enter image description here](https://i.stack.imgur.com/VLsCV.png)
Для сопоставления обоих файлов, которые я использую ниже:
import pandas as pd
names_array=[]
ratio_array=[]
def match_names(wrong_names,correct_names):
for row in wrong_names:
x=process.extractOne(row, correct_names)
names_array.append(x[0])
ratio_array.append(x[1])
return names_array,ratio_array
fields = ['name']
#Wrong country names dataset
df=pd.read_csv("wrong-country-names.csv",encoding="ISO-8859-1",sep=';', skipinitialspace=True, usecols= fields )
print(df.dtypes)
wrong_names=df.dropna().values
#Correct country names dataset
choices_df=pd.read_csv("country-names.csv",encoding="ISO-8859-1",sep='\t', skipinitialspace=True)
correct_names=choices_df.values
name_match,ratio_match=match_names(wrong_names,correct_names)
df['correct_country_name']=pd.Series(name_match)
df['country_names_ratio']=pd.Series(ratio_match)
df.to_csv("string_matched_country_names.csv")
print(df[['name','correct_country_name','country_names_ratio']].head(10))
Я получаю следующую ошибку:
name object
dtype: object
Traceback (most recent call last):
File "<ipython-input-221-a1fd87d9f661>", line 1, in <module>
runfile('C:/Users/Drashti Bhatt/Desktop/untitled0.py', wdir='C:/Users/Drashti Bhatt/Desktop')
File "C:\Users\Drashti Bhatt\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
execfile(filename, namespace)
File "C:\Users\Drashti Bhatt\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Drashti Bhatt/Desktop/untitled0.py", line 27, in <module>
name_match,ratio_match=match_names(wrong_names,correct_names)
File "C:/Users/Drashti Bhatt/Desktop/untitled0.py", line 9, in match_names
x=process.extractOne(row, correct_names)
File "C:\Users\Drashti Bhatt\Anaconda3\lib\site-packages\fuzzywuzzy\process.py", line 220, in extractOne
return max(best_list, key=lambda i: i[1])
File "C:\Users\Drashti Bhatt\Anaconda3\lib\site-packages\fuzzywuzzy\process.py", line 78, in extractWithoutOrder
processed_query = processor(query)
File "C:\Users\Drashti Bhatt\Anaconda3\lib\site-packages\fuzzywuzzy\utils.py", line 95, in full_process
string_out = StringProcessor.replace_non_letters_non_numbers_with_whitespace(s)
File "C:\Users\Drashti Bhatt\Anaconda3\lib\site-packages\fuzzywuzzy\string_processing.py", line 26, in replace_non_letters_non_numbers_with_whitespace
return cls.regex.sub(" ", a_string)
TypeError: expected string or bytes-like object
Я пытался с опцией .decode, но это не сработало.Что я делаю не так?Любая помощь по этому вопросу будет высоко ценится!Большое спасибо!