1
考虑pd.Series
s
熊猫系列下降时,多指标不是唯一
midx = pd.MultiIndex.from_product([list('ABC'), np.arange(3)])
s = pd.Series(1, midx)
s
A 0 1
1 1
2 1
B 0 1
1 1
2 1
C 0 1
1 1
2 1
dtype: int64
它是使用drop
非常方便摆脱横截面。例如
s.drop('A')
B 0 1
1 1
2 1
C 0 1
1 1
2 1
dtype: int64
但是,如果我赚了指数不唯一
s = s.append(pd.Series(0, pd.MultiIndex.from_tuples([('A', 2)]))).sort_index()
s
A 0 1
1 1
2 1
2 0
B 0 1
1 1
2 1
C 0 1
1 1
2 1
dtype: int64
那么同样drop
不再起作用。
s.drop('A')
A 0 1
1 1
2 1
2 0
B 0 1
1 1
2 1
C 0 1
1 1
2 1
dtype: int64
我怎么滴像期望的结果之前
应该是(这不起作用,哪些呢)
s.drop('B')
A 0 1
1 1
2 1
2 0
C 0 1
1 1
2 1
dtype: int64