[英]How do I extract the dictionary from a JSON file to a pandas Dataframe?
I've extracted the data into a JSON file (it is a nest filed) 我已经将数据提取到JSON文件中(这是一个嵌套文件)
I've read_json to extract the data into a pandas: 我已经read_json提取数据到熊猫:
df = pd.read_json('./data0000.json')
but got this as the data is nested ( all the fields are under Data): 但由于嵌套了数据而得到了此信息(所有字段都在Data下):
Data
0 {field 1, field 2, field 3....)
How do I unnest it in a panda dataframe? 如何在熊猫数据框中取消嵌套?
For the following data format, read_json() works as you would like: 对于以下数据格式,read_json()可以按照您的意愿工作:
[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]
We would still need to see your data for a full fix, but you may also want to explore the "orient" parameter in read_json(). 我们仍然需要查看您的数据以获取完整修复,但您可能还需要探索read_json()中的“ orient”参数。
data = pd.read_json('data0000.json',orient='records')
Allowed values for orient are: {'split','records','index','columns','values'} 允许的orient值为:{'split','records','index','columns','values'}
DataFrame
'columns'
'columns'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.