我有一个json文件,看起来像这样:
{'e': 'test', 'E': 1657471446261, 's': 'asset', 'b': [['20890.93000000', '0.00000000'], ['20889.96000000', '0.00000000']], 'a': [['20888.21000000', '0.00000000'], ['20888.28000000', '0.00000000'], ['20888.30000000', '0.00000000']]}
{'e': 'test', 'E': 1657471446260, 's': 'asset', 'b': [['20890.93000000', '0.00000000'], ['20889.96000000', '0.00000000']], 'a': [['20888.21000000', '0.00000000'], ['20888.28000000', '0.00000000'], ['20888.30000000', '0.00000000'], ['20888.42000000', '0.00000000']]}
我如何在python中以数据框或其他格式打开它,因为在任何情况下它都不起作用。或者将这种类型的json加载到数据框架中:
[
[
"19789.38000000",
"0.00000000"
],
[
"19788.19000000",
"0.00053000"
]
][
[
"19789.41000000",
"0.00000000"
],
[
"19789.05000000",
"0.00000000"
],
[
"19788.19000000",
"0.00000000"
]]
您可以使用此函数转换具有不规则索引值的字典。
import pandas as pd
data = {'e': 'test', 'E': 1657471446261, 's': 'asset', 'b': [['20890.93000000', '0.00000000'], ['20889.96000000', '0.00000000']], 'a': [['20888.21000000', '0.00000000'], ['20888.28000000', '0.00000000'], ['20888.30000000', '0.00000000']]}
df = pd.DataFrame({ key:pd.Series(value) for key, value in data.items() })
输出:
e E s b a
0 test 1.657471e+12 asset [20890.93000000, 0.00000000] [20888.21000000, 0.00000000]
1 NaN NaN NaN [20889.96000000, 0.00000000] [20888.28000000, 0.00000000]
2 NaN NaN NaN NaN [20888.30000000, 0.00000000]
我希望你在期待这个。