用法:
pandas.IndexSlice = <pandas.core.indexing._IndexSlice object>
創建一個對象以更輕鬆地執行multi-index 切片。
注意:
有關切片 MultiIndex 的更多信息,請參閱定義的級別。
例子:
>>> midx = pd.MultiIndex.from_product([['A0','A1'], ['B0','B1','B2','B3']]) >>> columns = ['foo', 'bar'] >>> dfmi = pd.DataFrame(np.arange(16).reshape((len(midx), len(columns))), ... index=midx, columns=columns)
使用默認切片命令:
>>> dfmi.loc[(slice(None), slice('B0', 'B1')),:] foo bar A0 B0 0 1 B1 2 3 A1 B0 8 9 B1 10 11
使用 IndexSlice 類獲得更直觀的命令:
>>> idx = pd.IndexSlice >>> dfmi.loc[idx[:, 'B0':'B1'],:] foo bar A0 B0 0 1 B1 2 3 A1 B0 8 9 B1 10 11
相關用法
- Python pandas.Index.value_counts用法及代碼示例
- Python pandas.Index.argmin用法及代碼示例
- Python pandas.Index.is_categorical用法及代碼示例
- Python pandas.Index.to_series用法及代碼示例
- Python pandas.Index.str用法及代碼示例
- Python pandas.Index.to_numpy用法及代碼示例
- Python pandas.Index.is_object用法及代碼示例
- Python pandas.Index.slice_indexer用法及代碼示例
- Python pandas.Index.is_interval用法及代碼示例
- Python pandas.Index.notnull用法及代碼示例
- Python pandas.Index.equals用法及代碼示例
- Python pandas.Index.set_names用法及代碼示例
- Python pandas.Index.searchsorted用法及代碼示例
- Python pandas.Index.duplicated用法及代碼示例
- Python pandas.Index.is_monotonic_increasing用法及代碼示例
- Python pandas.Index.min用法及代碼示例
- Python pandas.Index.is_monotonic_decreasing用法及代碼示例
- Python pandas.Index.max用法及代碼示例
- Python pandas.Index.shift用法及代碼示例
- Python pandas.Index.argmax用法及代碼示例
注:本文由純淨天空篩選整理自pandas.pydata.org大神的英文原創作品 pandas.IndexSlice。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。