数据帧中的ASCII和UTF问题

时间:2018-05-26 21:12:41

标签: python pandas dataframe urllib python-unicode

我有数据框,其中我有%22之类的符号,我正在尝试使用urllib替换它们。对于其他文件,此代码工作正常,但由于某种原因,我收到此错误。我有什么想法可以解决这个问题。据我所知,我使用的是utf-8。

df = pd.read_csv('Data\Genres\cleanedGenreArtistSong.csv',engine = 'python', encoding = 'utf-8-sig')
df['Song'] = df['Song'].apply(lambda x:urllib.unquote(x).decode('utf8') )

我得到的错误是:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 1: ordinal not in range(128)

这是我的数据框的快照:

enter image description here

0 个答案:

没有答案