我有一个pandas数据帧如下:
df=pd.DataFrame({'a':['red','yellow','blue'], 'b':[0,0,1], 'c':[0,1,0], 'd':[1,0,0]})
df
Run Code Online (Sandbox Code Playgroud)
看起来像
a b c d
0 red 0 0 1
1 yellow 0 1 0
2 blue 1 0 0
Run Code Online (Sandbox Code Playgroud)
我想将它转换为字典,以便我得到:
red d
yellow c
blue b
Run Code Online (Sandbox Code Playgroud)
如果数据集非常大,请避免使用任何迭代方法.我还没有找到解决方案.任何帮助表示赞赏.