我需要将带有字典值的字典转换为镶木地板,我的数据如下所示:
{"KEY":{"2018-12-06":250.0,"2018-12-07":234.0}}
我正在转换为 pandas 数据框,然后写入 pyarrow 表:
import pandas as pd
import pyarrow as pa
import pyarrow.parquet as pq
data = {"KEY":{"2018-12-06":250.0,"2018-12-07":234.0}}
df = pd.DataFrame.from_dict(data, orient='index')
table = pa.Table.from_pandas(df, preserve_index=False)
pq.write_table(table, 'file.parquet', flavor='spark')
我最终得到的数据只有日期和值,但没有字典的键:
{"2018-12-06":250.0,"2018-12-07":234.0}
我需要的是也有数据的关键:
{"KEY": {"2018-12-06":250.0,"2018-12-07":234.0}}