【发布时间】:2017-05-02 17:49:52
【问题描述】:
如何从 pandas 数据框的列创建字典。这是测试代码:
import pandas as pd
df = pd.DataFrame({
'c0': ['A','A','B'],
'c1': ['b','c','d'],
'c2': [1, 3,4],
'c3': [5,7,8]})
输出:
c0 c1 c2 c3
0 A b 1 5
1 A c 3 7
2 B d 4 8
我想从 key:(c0, c1) 和 value:(c2) 中获取字典
{('A', 'b'): 1, ('A', 'c'): 3, ('B', 'd'): 4}
【问题讨论】:
标签: python pandas dictionary tuples