【发布时间】:2018-01-16 15:32:11
【问题描述】:
我有这个熊猫 df:
value
index1 index2 index3
1 1 1 10.0
2 -0.5
3 0.0
2 2 1 3.0
2 0.0
3 0.0
3 1 0.0
2 -5.0
3 6.0
我想使用 dict 获取特定索引组合的“值”。
通常,我使用,例如:
df = df.iloc[df.index.isin([2],level='index1')]
df = df.iloc[df.index.isin([3],level='index2')]
df = df.iloc[df.index.isin([2],level='index3')]
value = df.values[0][0]
现在,我想使用这本字典以更短的方式获得我的值 = -5:
d = {'index1':2,'index2':3,'index3':2}
而且,如果我使用:
d = {'index1':2,'index2':3}
我想得到数组:
[0.0, -5.0, 6.0]
提示?
【问题讨论】:
标签: pandas dictionary