pandas手册(用一个总结一个)

DataFrame.filter(items = None,like=None,regex=None,axis=None)

例子:

>>> 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

pandas的map映射()

import pandas as pd
# s = pd.DataFrame({'one':[1,2,3],'two':[4,5,6],'three':[7,8,9]},dtype='category')
s = pd.DataFrame({'one':[1,1,2,2,1],'two':[1,2,3,4,5]},dtype='category')
s['one'] = s['one'].map({1:'a',2:'b'})
print(s)

输出:
  one two
0   a   1
1   a   2
2   b   3
3   b   4
4   a   5

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值