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']
View Code

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

 

posted @ 2020-09-15 11:47  Big_river  阅读(218)  评论(0编辑  收藏  举报