閱讀 JSON
可以將 json 的字串或檔案路徑傳遞給具有有效 json 的檔案
In [99]: pd.read_json('[{"A": 1, "B": 2}, {"A": 3, "B": 4}]')
Out[99]:
A B
0 1 2
1 3 4
另外,為了節省記憶體:
with open('test.json') as f:
data = pd.DataFrame(json.loads(line) for line in f)
In [99]: pd.read_json('[{"A": 1, "B": 2}, {"A": 3, "B": 4}]')
Out[99]:
A B
0 1 2
1 3 4
另外,為了節省記憶體:
with open('test.json') as f:
data = pd.DataFrame(json.loads(line) for line in f)