简体   繁体   English

如何将字典从JSON文件提取到pandas Dataframe?

[英]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'}

From the docs link : 从文档链接

  • DataFrame

    • default is 'columns' 默认为'columns'
    • allowed values are: {'split','records','index','columns','values'} 允许的值包括:{'split','records','index','columns','values'}
    • The DataFrame index must be unique for orients 'index' and 'columns'. DataFrame索引对于东方的“索引”和“列”必须是唯一的。
    • The DataFrame columns must be unique for orients 'index', 'columns', and 'records'. 对于“索引”,“列”和“记录”而言,DataFrame列必须唯一。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用矢量化操作从 pandas dataframe 创建特定的嵌套格式 JSON 或字典? - How do I create a specific nesting format JSON or dictionary from a pandas dataframe using vectorized operations? 试图从Python中的pandas数据框中提取一个看起来像JSON的列,我如何实现这一点? - Trying to extract one column that seems to be JSON from a pandas dataframe in Python , how do I achieve this? 如何提取 3 级字典最内层字典的值并将这些值保存在 Pandas DataFrame 中? - How do I extract the values of the innermost dictionary of a 3-level dictionary and save those values in a Pandas DataFrame? 如何从具有特定格式的 Pandas 数据框创建字典 - How do I create a dictionary from a Pandas dataframe with a specific format 如何从熊猫数据框中提取日期/年/月? - How do I extract the date/year/month from pandas dataframe? 如何从 pandas dataframe 列的列表中提取元素? - How do I extract elements from a list in a pandas dataframe column? 如何从 Pandas DataFrame 中提取列表列表? - How do I extract a list of lists from a Pandas DataFrame? 我无法从 pandas dataframe 字典中提取字符串 - I am unable to extract a string from within a pandas dataframe dictionary pandas中如何从深度字典中提取键值 || Python || dataframe - How to extract key value from deep dictionary in pandas || Python || dataframe 如何从 Python Pandas Dataframe 的 STRING 列中提取嵌套字典? - How to extract a nested dictionary from a STRING column in Python Pandas Dataframe?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM