用法:
Series.filter(items=None, like=None, regex=None, axis=None)
根據指定的索引標簽對 DataFrame 行或列進行子集。
請注意,此例程不會根據其內容過濾 DataFrame 。過濾器應用於索引的標簽。
- items:list-like
保留項目中的軸標簽。
- like:str
保留“like in label == True”軸的標簽。
- regex:str(正則表達式)
保留 re.search(regex, label) == True 的軸的標簽。
- axis:{0 或‘index’,1 或‘columns’,無},默認無
要過濾的軸,表示為索引 (int) 或軸名稱 (str)。默認情況下,這是信息軸,‘index’ 用於係列,‘columns’ 用於 DataFrame。
- 與輸入對象相同的類型
參數:
返回:
注意:
items
、like
和regex
參數強製互斥。axis
默認為使用[]
進行索引時使用的信息軸。例子:
>>> df = pd.DataFrame(np.array(([1, 2, 3], [4, 5, 6])), ... index=['mouse', 'rabbit'], ... columns=['one', 'two', 'three']) >>> df one two three mouse 1 2 3 rabbit 4 5 6
>>> # select columns by name >>> df.filter(items=['one', 'three']) one three mouse 1 3 rabbit 4 6
>>> # select columns by regular expression >>> df.filter(regex='e$', axis=1) one three mouse 1 3 rabbit 4 6
>>> # select rows containing 'bbi' >>> df.filter(like='bbi', axis=0) one two three rabbit 4 5 6
相關用法
- Python pandas.Series.fillna用法及代碼示例
- Python pandas.Series.first用法及代碼示例
- Python pandas.Series.floordiv用法及代碼示例
- Python pandas.Series.factorize用法及代碼示例
- Python pandas.Series.flags用法及代碼示例
- Python pandas.Series.add_prefix用法及代碼示例
- Python pandas.Series.map用法及代碼示例
- Python pandas.Series.max用法及代碼示例
- Python pandas.Series.str.isdecimal用法及代碼示例
- Python pandas.Series.str.get用法及代碼示例
- Python pandas.Series.to_csv用法及代碼示例
- Python pandas.Series.dt.day_name用法及代碼示例
- Python pandas.Series.sample用法及代碼示例
- Python pandas.Series.head用法及代碼示例
- Python pandas.Series.eq用法及代碼示例
- Python pandas.Series.plot.line用法及代碼示例
- Python pandas.Series.to_pickle用法及代碼示例
- Python pandas.Series.between_time用法及代碼示例
- Python pandas.Series.reindex_like用法及代碼示例
- Python pandas.Series.dt.is_year_end用法及代碼示例
注:本文由純淨天空篩選整理自pandas.pydata.org大神的英文原創作品 pandas.Series.filter。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。