Reading multiple JSON records into a Pandas dataframe

前端 未结 4 803
粉色の甜心
粉色の甜心 2020-12-04 17:41

I\'d like to know if there is a memory efficient way of reading multi record JSON file ( each line is a JSON dict) into a pandas dataframe. Below is a 2 line example with wo

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

    If you are trying to save memory, then reading the file a line at a time will be much more memory efficient:

    with open('test.json') as f:
        data = pd.DataFrame(json.loads(line) for line in f)
    

    Also, if you import simplejson as json, the compiled C extensions included with simplejson are much faster than the pure-Python json module.

提交回复
热议问题