我有一个数据框,我希望它选择一些列并以某种方式将其转换为Dictionary
数据框:
这是我想要的输出
{20: [4.6, 4.3, 4.3, 20],
21: [4.6, 4.3, 4.3, 21],
22: [6.0, 5.6, 9.0, 22],
23: [8.75, 5.6, 6.6, 23]}
我已经尝试过了
items_dic = data[["Length","Width","Height","Pid" ]].set_index('Pid').T.to_dict('list')
items_dic = {20: [4.6, 4.3, 4.3],
21: [4.6, 4.3, 4.3],
22: [6.0, 5.6, 9.0],
23: [8.75, 5.6, 6.6]}
,但这不包括值列表中的Pid 有人可以解释为什么吗?
答案 0 :(得分:11)
在DataFrame.set_index
中设置参数curl: (3) URL using bad/illegal format or missing URL
Makefile:35: recipe for target 'something' failed
make: *** [savetradesdbscheme] Error 3
,因为默认参数drop=False
将列移到索引:
drop=False