4
特定行我有一个多指标数据帧,看起来像这样:掉落从多指标数据帧
start grad
1995-96 1995-96 15 15
1996-97 6 6
2002-03 1 1
2007-08 1 1
我想用的具体数值为第一电平(电平= 0)下降。在这种情况下,我想放弃1995年至1996年在第一个索引中的所有内容。
特定行我有一个多指标数据帧,看起来像这样:掉落从多指标数据帧
start grad
1995-96 1995-96 15 15
1996-97 6 6
2002-03 1 1
2007-08 1 1
我想用的具体数值为第一电平(电平= 0)下降。在这种情况下,我想放弃1995年至1996年在第一个索引中的所有内容。
pandas.DataFrame.drop
需要水平作为可选参数
df.drop('1995-96', level='start')
由于v0.18.1,它的文档字符串说:
""" Signature: df.drop(labels, axis=0, level=None, inplace=False, errors='raise') Docstring: Return new object with labels in requested axis removed. Parameters ---------- labels : single label or list-like axis : int or axis name level : int or level name, default None For MultiIndex inplace : bool, default False If True, do operation inplace and return None. errors : {'ignore', 'raise'}, default 'raise' If 'ignore', suppress error and existing labels are dropped. .. versionadded:: 0.16.1 """
如果第一个索引没有被命名为'start',那么可以使用'level = 0' – dreme
有更好的方式,但:'DF。 select(lambda row:row [0]!='1995-96',axis = 0)' –