用法:
Series.drop(labels=None, axis=0, index=None, columns=None, level=None, inplace=False, errors='raise')
返回刪除指定索引標簽的係列。
根據指定的索引標簽刪除係列的元素。使用multi-index 時,可以通過指定級別來移除不同級別的標簽。
- labels:單標簽或list-like
要刪除的索引標簽。
- axis:0,默認 0
為係列上的應用程序提供冗餘。
- index:單標簽或list-like
Series 上的應用程序冗餘,但可以使用 ‘index’ 代替 ‘labels’。
- columns:單標簽或list-like
係列沒有變化;請改用‘index’ or ‘labels’。
- level:int 或級別名稱,可選
對於 MultiIndex,將刪除標簽的級別。
- inplace:布爾值,默認為 False
如果為 True,則在原地執行操作並返回 None。
- errors:{‘ignore’, ‘raise’},默認 ‘raise’
如果‘ignore’,抑製錯誤並且僅刪除現有標簽。
- 係列或無
刪除了指定索引標簽的係列,如果
inplace=True
則為無。
- KeyError
如果在索引中找不到任何標簽。
參數:
返回:
拋出:
例子:
>>> s = pd.Series(data=np.arange(3), index=['A', 'B', 'C']) >>> s A 0 B 1 C 2 dtype: int64
放置標簽 B 和 C
>>> s.drop(labels=['B', 'C']) A 0 dtype: int64
在 MultiIndex 係列中刪除第二級標簽
>>> midx = pd.MultiIndex(levels=[['lama', 'cow', 'falcon'], ... ['speed', 'weight', 'length']], ... codes=[[0, 0, 0, 1, 1, 1, 2, 2, 2], ... [0, 1, 2, 0, 1, 2, 0, 1, 2]]) >>> s = pd.Series([45, 200, 1.2, 30, 250, 1.5, 320, 1, 0.3], ... index=midx) >>> s lama speed 45.0 weight 200.0 length 1.2 cow speed 30.0 weight 250.0 length 1.5 falcon speed 320.0 weight 1.0 length 0.3 dtype: float64
>>> s.drop(labels='weight', level=1) lama speed 45.0 length 1.2 cow speed 30.0 length 1.5 falcon speed 320.0 length 0.3 dtype: float64
相關用法
- Python pandas.Series.dropna用法及代碼示例
- Python pandas.Series.drop_duplicates用法及代碼示例
- Python pandas.Series.droplevel用法及代碼示例
- Python pandas.Series.dt.day_name用法及代碼示例
- Python pandas.Series.dt.is_year_end用法及代碼示例
- Python pandas.Series.divide用法及代碼示例
- Python pandas.Series.dt.weekday用法及代碼示例
- Python pandas.Series.div用法及代碼示例
- Python pandas.Series.dt.to_pydatetime用法及代碼示例
- Python pandas.Series.dt.second用法及代碼示例
- Python pandas.Series.dt.tz_localize用法及代碼示例
- Python pandas.Series.dt.is_leap_year用法及代碼示例
- Python pandas.Series.divmod用法及代碼示例
- Python pandas.Series.dt.is_quarter_start用法及代碼示例
- Python pandas.Series.dot用法及代碼示例
- Python pandas.Series.dt.tz_convert用法及代碼示例
- Python pandas.Series.dt.round用法及代碼示例
- Python pandas.Series.dt.nanosecond用法及代碼示例
- Python pandas.Series.dt.to_period用法及代碼示例
- Python pandas.Series.dt.ceil用法及代碼示例
注:本文由純淨天空篩選整理自pandas.pydata.org大神的英文原創作品 pandas.Series.drop。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。