我是Python的新手(正在使用python 3),并且试图在Jupyter笔记本中导入JSON文件。但是,它给出以下错误:
this.props.navigation.getParam("data", defaultValue)
下面是代码:
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 4276350: character maps to <undefined>
我将不胜感激。
答案 0 :(得分:2)
假设this是您要导入的文件,它实际上是许多JSON对象,每行一个。您需要通过指定lines=True
逐行导入它:
data = pd.read_json(datafile, lines=True, orient='columns', encoding='utf-8')
此外,将文件路径作为第一个参数传递,而不是文件内容。您可以摆脱打开文件的代码。此外,pd.read_json
返回了一个DataFrame,不需要程序的最后一行:
>>> data = pd.read_json('yelp_academic_dataset_business.json', lines=True, orient='columns', encoding='utf-8')
>>> data
attributes business_id categories city ... review_count stars state type
0 {'Take-out': False, 'Wi-Fi': 'free', 'Good For... O_X3PGhk3Y5JWVi866qlJg [Active Life, Arts & Entertainment, Stadiums &... Phoenix ... 29 4.0 AZ business
1 {'Parking': {'garage': False, 'street': False,... QbrM7wqtmoNncqjc6GtFaQ [Tires, Automotive, Fashion, Shopping, Departm... Glendale ... 3 3.5 AZ business