简体   繁体   English

如何将我的json数据转换为dataframe pandas

[英]How to convert my json data to dataframe pandas

Hi i cannot seem to convert my json data to csv using python please help: 嗨,我似乎无法使用python将我的json数据转换为csv请帮助:

{
    "metadata": {
        "application": "orders-prod",
        "host": "ldn001"

    },
    "OrdID": "123",
    "EventSeq": "328",
    "EventTS": "2019-04-17T01:01:14.569000Z"

}
{
    "metadata": {
        "application": "orders-prod",
        "host": "ldn001"

    },
    "OrdID": "234",
    "EventSeq": "328",
    "EventTS": "2019-04-17T01:01:14.569000Z"

}
{
    "metadata": {
        "application": "orders-prod",
        "host": "ldn001"

    },
    "OrdID": "554",
    "EventSeq": "328",
    "EventTS": "2019-04-17T01:01:14.569000Z"

}

df=pd.read_json('smallordersl.json',lines=True)

I tried the above but it doesn't work- i get the error ValueError: Expected object or value. 我尝试了上面但它不起作用 - 我得到错误ValueError:预期的对象或值。

Your json file is not per line as you specified. 您的json文件不是您指定的每行。 See below notes in the documentation about reading json files. 请参阅有关阅读json文件的文档中的以下注释。 https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_json.html https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_json.html

lines : boolean, default False
Read the file as a json object per line.

Below is an example of using lines=True in the parameter 下面是在参数中使用lines = True的示例

pd.read_json('{"a":1,"b":2}\n{"a":3,"b":4}', lines=True)

Notice that the json file above has line1 and line2, separated by a new line (\\n) 请注意,上面的json文件包含line1和line2,用新行分隔(\\ n)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM