我有一个任务,我正在尝试加载营养素.json文件放入熊猫数据框。我使用的是python3.5 我试过两种方法
数据源=pd.read_json文件("营养素.json“)
这将产生一个错误“ValueError:training data”
2。 #将整个文件读入python数组 打开('营养素.json','rb')作为f: 数据=f.readlines()
# remove the trailing "\n" from each line
data = map(lambda x: x.rstrip(), data)
data = map(str, data)
# each element of 'data' is an individual JSON object.
# i want to convert it into an *array* of JSON objects
# which, in and of itself, is one large JSON object
# basically... add square brackets to the beginning
# and end, and have all the individual business JSON objects
# separated by a comma
data_json_str = "[" + ','.join(data) + "]"
# now, load it into pandas
data_df = pd.read_json(data_json_str)
这就产生了一个错误
ValueError:应为对象或值
在营养素.json是我使用下面的说明提取的文件。它是一个335 Mb的文件。你能帮我一下吗。在
非常感谢你
从https://github.com/schirinos/nutrient-db.git查看GitHub中的nutrition db python实用程序
把你的档案查一遍jsonlint.com网站查看文件是否正确格式化为json。在
您的第一次尝试书写正确:
相关问题 更多 >
编程相关推荐