首页 > 解决方案 > Python 数据框到字典列表

问题描述

我希望将我的数据框转换为以下格式,但对字典的格式感到困惑。我该怎么做?

df.headers() = ['Date','Label','Category']

所需格式

fig['layout']['annotations'] = [dict(x=df['Date'],y=df['Label'],text=df['Label']),
                                    dict(x=df['Date'],y=df['Label'],text=df['Label']...)]

样本

fig['layout']['annotations'] = [dict(x='2022-12-07 00:00:00',y=63,text="This is a label"),
                                    dict(x='2021-11-01 00:00:00',y=15,text="Testing")]

在此处输入图像描述

标签: pythonpython-3.xpandas

解决方案


推荐阅读