How to read a large json in pandas?

后端 未结 2 689
悲哀的现实
悲哀的现实 2021-02-08 10:31

My code is :data_review=pd.read_json(\'review.json\') I have the data review as fllow:

{
    // string, 22 character unique review id
         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-08 11:07

    If you don't want to use a for-loop, the following should do the trick:

    import pandas as pd
    
    df = pd.read_json("foo.json", lines=True)
    

    This will handle the case where your json file looks similar to this:

    {"foo": "bar"}
    {"foo": "baz"}
    {"foo": "qux"}
    

    And will turn it into a DataFrame consisting of a single column, foo, with three rows.

    You can read more at Panda's docs

提交回复
热议问题