python - 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")]
解决方案
推荐阅读
- c# - EF Core Remove-Migration 错误:对象引用未设置为对象的实例
- python - 查找所有组合以将单个列表拆分为两个列表
- nativescript - 在 NativeScript 中有没有办法跨平台安排后台作业?
- iis - iis 10 中的 URL 重写模式
- java - 我想在我的 Homefragment.java 类的 recyclerview 中添加水平滚动的卡片视图
- swift - 如何构建顶部和底部白色的集合视图控制器?
- javascript - 如何知道在动态生成的选项卡集中选择并激活了哪个选项卡
- c# - 如何在 WPF 中创建一个通用视图并且应该在所有模块中引用?
- php - 如何将会话值与php中的多个文件夹名称进行比较?
- marklogic - 注册查询在 MarkLogic 中是如何工作的?