用法:
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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。