Numpy学习---字符串处理

学习时,借鉴正常处理字符串的几个基本函数,较容易掌握
1.add()

import numpy as np
#caes1: strings
print(np.char.add('multiple\t'v,'alue'))  #相接不留痕
# multiple value 
#case2: array
print(np.char.add(['aaa','bbb'],['ccc','ddd'])) #对应元素相接
#  ['aaaccc' 'bbbddd']

2.multiply()

>>> print(np.char.multiply('blog',4))
blogblogblogblog

3.center()

>>> print(np.char.center('cumt',20,fillchar='@'))
@@@@@@@@cumt@@@@@@@@

4.capitalize()

>>> print(np.char.capitalize('cumt'))
Cumt

5.title()

>>> print(np.char.title('cumt is china university of mining and technology'))
Cumt Is China University Of Mining And Technology

capitalize 与 title 区别在于:title会将每个单词的首字母大写
6.lower() 和 upper()

>>> print(np.char.lower('I Like Data'))
i like data
>>> print(np.char.upper('i like data'))
I LIKE DATA

7.split()

#默认分隔符为空格
>>> print(np.char.split(' Central Limit Therom'))
['Central', 'Limit', 'Therom']
#指定分隔符
>>> print(np.char.split('Central,limit,therom',','))
['Central', 'limit', 'therom']

7.splitlines()

#分割换行符
>>> print(np.char.splitlines('Central Limit\nTherom'))
['Central Limit', 'Therom']
>>> print(np.char.splitlines('Central\rLimit Therom'))
['Central', 'Limit Therom']

8.strip()

>>> print(np.char.strip('Central limit therom','c')) #区别大小写
Central limit therom
>>> print(np.char.strip('Central limit therom','m'))
Central limit thero

8.join()

>>> print(np.char.join('@','cumt'))
c@u@m@t
>>> print(np.char.join(['@','¥'],['cumt','rmb']))
['c@u@m@t' 'r¥m¥b']

10.replace()

>>> print(np.char.replace('bar-plot','bar','scattter'))
scattter-plot

11.strip()

>>> print(np.char.strip('Central limit therom','c'))
Central limit therom
>>> print(np.char.strip('Central limit therom','m'))
Central limit thero
>>> print(np.char.strip(' limit '))
limit
>>> print(np.char.strip(['Central','domain','function','notation','node'],'n'))
['Central' 'domai' 'functio' 'otatio' 'ode']
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值