pandas.Panel.filter

Panel.filter(items=None, like=None, regex=None, axis=None)[source]

子集根据指定索引中的标签的数据帧的行或列。

请注意,此例程不会对其内容过滤数据帧。过滤器应用于索引的标签。

参数:

项目:list-like

要限制的信息轴列表(不能全部存在)

like:string

保持信息轴在“arg in col == True”

regex:string(regular expression)

保持信息轴与re.search(regex,col)== True

axis:int或字符串轴名称

过滤轴。默认情况下,这是信息轴,“index”为系列,“列”为DataFrame

返回:

与输入对象类型相同

也可以看看

pandas.DataFrame.select

笔记

itemslikeregex参数被强制为互斥。

axis默认为使用[]编制索引时使用的信息轴。

例子

>>> 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
Scroll To Top