我试图使用pd.read_csv打开Kaggle Spotify排名前50位的歌曲CSV文件,但出现以下错误:“'utf-8'编解码器无法解码位置2的字节0xf1:无效的连续字节”
在excel中,它看起来像一个普通的csv文件。我尝试使用csv.reader方法,并使用defaultdict和一些for循环来打开。为什么pd.read_csv无法工作?
链接到Kaggle CSV文件以方便使用:https : //www.kaggle.com/leonardopena/top50spotify2019
将编码设置为latin-1:
import pandas as pd
df = pd.read_csv('datasets_456958_861311_top50contry.csv',
encoding='latin-1'
)
print(df.head())
输出:
Unnamed: 0 title artist ... spch pop country
0 1 Dance Monkey Tones and I ... 9.0 100 world
1 2 ROXANNE Arizona Zervas ... 15.0 99 world
2 3 Memories Maroon 5 ... 5.0 99 world
3 4 Circles Post Malone ... 4.0 99 world
4 5 All I Want for Christmas Is You Mariah Carey ... 4.0 98 world
[5 rows x 17 columns]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句