【发布时间】:2021-07-21 13:07:04
【问题描述】:
我在 pandas 中有以下数据框:
US46434V7617 US3160928731 US4642865251
2021-07-20 13.741297 53.793367 104.151499
如何将其转换为以列为键、以列值为值的字典。例如:
[{'US46434V7617': 13.741297048948578, 'US3160928731': 53.7933674972021, 'US4642865251': 104.15149908700006}]
【问题讨论】:
-
索引怎么样。 . .你在找
df.to_dict(orient='index')吗?还是你想要orient='records' -
在进行编辑之前,请注意您想要获得的是 set 的 3 个 dictionaries。因为字典是unhashable,所以python中不存在这样的对象。