2016-08-30 81 views
4

特定行我有一個多指標數據幀,看起來像這樣:掉落從多指標數據幀

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

我想用的具體數值爲第一電平(電平= 0)下降。在這種情況下,我想放棄1995年至1996年在第一個索引中的所有內容。

+0

有更好的方式,但:'DF。 select(lambda row:row [0]!='1995-96',axis = 0)' –

回答

7

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

如果第一個索引沒有被命名爲'start',那麼可以使用'level = 0' – dreme