Loading a file with more than one line of JSON into Pandas

前端 未结 4 707
终归单人心
终归单人心 2020-12-04 10:21

I am trying to read in a JSON file into Python pandas (0.14.0) data frame. Here is the first line line of the JSON file:

{\"votes\": {\"funny\": 0, \"useful\         


        
4条回答
  •  天涯浪人
    2020-12-04 11:11

    I had a similar problem.

    It turns out that pd.read_json(myfile.json) will search in the parent folder automatically, but it returns this 'trailing data' error if you're not in the same folder as the file.

    I figured it out, because when I tried to do it with open('myfile.json', 'r'), and I got a FileNotFound error, so I checked the paths.

    I had failed to move myfile.json into the same folder as my notebook.

    Changing it to pd.read_json('../myfile.json') just worked.

提交回复
热议问题