import pandas as pd
import json
with open("review.json",encoding="utf8",) as f:
data = [json.loads(line) for line in f]
data
数据就像:
[{'review_id': 'Q1sbwvVQXV2734tPgoKj4Q',
'user_id': 'hG7b0MtEbXx5QzbzE6C_VA',
'business_id': 'ujmEBvifdJM6h6RLv4wQIg',
'stars': 1.0,
'useful': 6,
'funny': 1,
'cool': 0,
'text': 'Total bill for this horrible service? Over $8Gs. These crooks actually had the nerve to charge us $69 for 3 pills. I checked online the pills can be had for 19 cents EACH! Avoid Hospital ERs at all costs.',
'date': '2013-05-07 04:34:36'},
{'review_id': 'GJXCdrto3ASJOqKeVWPi6Q',
'user_id': 'yXQM5uF2jS6es16SJzNHfg',
'business_id': 'NZnhc2sEQy3RmzKTZnqtwQ',
'stars': 5.0,
'useful': 0,
'funny': 0,
'cool': 0,
运行代码时,整个数据未显示在输出控制台上。我正在使用python 3.6。请帮助
答案 0 :(得分:0)
尝试导入ijson库-一个将与JSON一起作为流而不是作为块文件使用的模块。
import ijson
f = open("review.json")
for item in ijson.items(f, "item"):
print str(o) + "\n"