我正在读取CSV并进行一些数据清除,但出现以下错误...
UnicodeEncodeError:'charmap'编解码器无法在位置6193编码字符'\ x96':字符映射为未定义
如果我注释掉sort_values
或drop_duplicates
函数,则不会产生错误。如何解决此错误?我是一个初学者,今天已经花了几个小时尝试用Google搜索答案,但是我什么都没有。下面的代码...
import pandas as pd
theData = pd.read_csv(r'my.csv', encoding='latin1')
theData = theData.drop_duplicates(subset=['BROADCAST','ARTIST','SONG','LABEL','ALBUM'])
epNums = theData['BROADCAST'].str[15:]
epNums = epNums.str[:3]
theData['ep num'] = epNums
theData['ep num'] = theData['ep num'].astype(int)
theData = theData.sort_values(by=['ep num'])
print(theData)
此错误似乎仅在我的PC上发生,因为它在我朋友的Mac上正常工作。但是解决问题的方法是将encoding=
替换为engine='python
。