def gen():
yield '1','2',1,2
yield '1','2',1,2
yield '1','3',1,2
yield '2','4',1,2
df = pd.DataFrame(gen(), columns=["a", "b", "c", "d",]).set_index(["a", "b"])
print df # ('a','b') --> ('c','d')
我们有:
c d
a b
1 2 1 2
2 1 2
3 1 2
2 4 1 2
访问时:
print df.loc[('1','3')] # Success
print df.at[('1','3')] # KeyError: '3'
另请注意,这也失败了,df是一个系列:
print df['c'].at[('1','3')] # TypeError: _get_value() got multiple values for keyword argument 'takeable'