Reading Json file as Pandas Dataframe error

前端 未结 4 1954
小鲜肉
小鲜肉 2020-12-14 02:33

I have a Json file as follows. It\'s a list of dicts.

[{\"city\": \"ab\", \"trips\": 4, \"date\": \"2014-01-25\", \"value\": 4.7, \"price\": 1.1, \"request_         


        
4条回答
  •  渐次进展
    2020-12-14 03:11

    You need to indicate to Pandas that "records" formatting (where the JSON appears like a list of dictionaries) is used in datasets.json.

    res = pd.read_json('input/dataset.json', orient='records')
    
    print(res.iloc[:, :5])
       %price  Weekly_pct  avg_dist  avg_price city
    0    15.4        46.2      3.67          5   ab
    1     0.0         NaN      8.26          5   bc
    

提交回复
热议问题