繁体   English   中英

从多索引Dataframe中删除特定行

[英]Drop specific rows from multiindex Dataframe

我有一个多索引数据框,如下所示:

 start      grad
 1995-96    1995-96 15  15  
            1996-97 6   6   
            2002-03 1   1   
            2007-08 1   1   

我想降低第一级的特定值(级别= 0)。 在这种情况下,我想放弃第一个索引中1995-96的所有内容。

pandas.DataFrame.drop将level作为可选参数

df.drop('1995-96', level='start')

从v0.18.1开始,它的docstring说:

 """ 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 """ 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM