用法:
Series.droplevel(level, axis=0)
返回刪除了請求的索引/列級別的係列/數據幀。
- level:int、str 或 list-like
如果給定字符串,則必須是級別的名稱如果list-like,元素必須是級別的名稱或位置索引。
- axis:{0 或 ‘index’,1 或 ‘columns’},默認 0
移除關卡的軸:
0 或‘index’:刪除列中的級別。
1 或‘columns’:刪除行中的級別。
- 係列/ DataFrame
刪除了請求的索引/列級別的係列/數據幀。
參數:
返回:
例子:
>>> df = pd.DataFrame([ ... [1, 2, 3, 4], ... [5, 6, 7, 8], ... [9, 10, 11, 12] ... ]).set_index([0, 1]).rename_axis(['a', 'b'])
>>> df.columns = pd.MultiIndex.from_tuples([ ... ('c', 'e'), ('d', 'f') ... ], names=['level_1', 'level_2'])
>>> df level_1 c d level_2 e f a b 1 2 3 4 5 6 7 8 9 10 11 12
>>> df.droplevel('a') level_1 c d level_2 e f b 2 3 4 6 7 8 10 11 12
>>> df.droplevel('level_2', axis=1) level_1 c d a b 1 2 3 4 5 6 7 8 9 10 11 12
相關用法
- Python pandas.Series.drop用法及代碼示例
- Python pandas.Series.dropna用法及代碼示例
- Python pandas.Series.drop_duplicates用法及代碼示例
- 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.droplevel。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。