pandas.read_json(path_or_buf=None, orient=None, typ='frame', dtype=True,
convert_axes=True, convert_dates=True, keep_default_dates=True,
numpy=False, precise_float=False, date_unit=None, encoding=None,
lines=False, chunksize=None, compression='infer')
其中,orient是用来指定传入的json字符串类型。
{index: [index], columns: [columns], data: [values]}
index作为索引, columns作为列名结合data的values组成一个dataframe
s = "{'index': [1, 2, 3], 'columns: ['a', 'b'], 'data':[[1, 3], [2, 8], [3, 9]]}"
pd.read_json(s, orient='split')
[{column1: value1, column2: value2}, …, {column1: value1, column2: value2}]
键column为列名,value为列所对应的值,每一个字典成员就构成了dataframe的一行数据
s = "[{'a': 1, 'b': 3}, {'a': 2, 'b': 6}, {'a': 3, 'b': 9}]"
pd.read_json(s, orient='records')
将key作为dataframe的index,字典中的键和键值构成dataframe的data
{index1: {column1: value1, column2: value2}, index2: {column1: value1, column2: value2}}
s = "{'0': {'a': 1, 'b': 2}, '1': {'a': 9, 'b': 11}}"
pd.read_json(s, orient='index')
{column1:{index1: value1, index2: value1}, column2:{index1: value2, index2: value2}}
将column作为列名,index作为索引,value为列的数据,组成一个dataframe
s = "{'a': {'0': 1, '1': 9}, 'b': {'0': 2, '1': 11}}"
pd.read_json(s, orient='columns'
[[value1, value2], …, [value1, value2]]
s = "[['a', 1], ['b', 2]]"
pd.read_json(s, orient='values')