Closed
Description
mulitindex slicing returns different (from pandas<=1.0.x) results in pandas 1.1.0rc0
df = pd.DataFrame( data=[[0,1,'a',1],[1,0,'a',0],[1,1,'b',1],[1,1,'c',2]], columns=['index','date','author','price'] )
# to keep the most recent date for every index (could happen in practice)
idx = df.drop_duplicates('index',keep='last').set_index(['index','date']).index
df.set_index(['index','date']).loc[idx,:].reset_index()
df
index | date | author | price |
---|---|---|---|
0 | 1 | a | 1 |
1 | 0 | a | 0 |
1 | 1 | b | 1 |
1 | 1 | c | 2 |
Result
author | price | |
---|---|---|
(0, 1) | a | 1 |
(1, 1) | b | 1 |
(1, 1) | c | 2 |