filter函数根据指定的索引标签对数据框按行或列进行数据筛选。用法如下:
'''
filter函数用法:参数items,like,regex互斥。主要对行和列的索引去过滤
axis参数:表示信息轴(要过滤的轴),Series对象index为过滤轴,DataFrame用columns为过滤轴。0或'index',1或'columns',默认None。
返回值:和对象本身类型一致。
'''
df = pd.DataFrame(np.array(([1, 2, 3], [4, 5, 6])), index=['mouse', 'rabbit'], columns=['one', 'two', 'three'])
df.filter(items=['one', 'three']) # 取列名为one和three两列的数据
df.filter(regex='e$', axis=1) # 取列名以e结尾的
df.filter(regex='a$', axis=0) # 取索引以a结尾的
df.filter(like='bbi', axis=0) # 取行索引(标签索引)包含bbi的
```python

4698

被折叠的 条评论
为什么被折叠?



