Pandas Replace All But Middle Values per Category of a Level with Blank
问题 Given the following pivot table: df=pd.DataFrame({'A':['a','a','a','a','a','b','b','b','b'], 'B':['x','y','z','x','y','z','x','y','z'], 'C':['a','b','a','b','a','b','a','b','a'], 'D':[7,5,3,4,1,6,5,3,1]}) table = pd.pivot_table(df, index=['A', 'B','C'],aggfunc='sum') table D A B C a x a 7 b 4 y a 1 b 5 z a 3 b x a 5 y b 3 z a 1 b 6 I know that I can access the values of each level like so: In [128]: table.index.get_level_values('B') Out[128]: Index(['x', 'x', 'y', 'y', 'z', 'x', 'y', 'z', 'z'