Python~Pandas 文本数据方法 cat()

cat()连接字符串 

Series.str.cat(others=None, sep=None, na_rep=None) 
参数: 
others : 列表或复合列表,默认为None,如果为None则连接本身的元素 
sep : 字符串 或者None,默认为None 
na_rep : 字符串或者 None, 默认 None。如果为None缺失值将被忽略。 
返回值: 
concat : 序列(Series)/索引(Index)/字符串(str)

#如果连接的是两个序列,则会对应
>>> Series(['a', 'b', 'c']).str.cat(['A', 'B', 'C'], sep=',')
0    a,A
1    b,B
2    c,C
dtype: object
#否则则会连接自身序列里的值
>>> Series(['a', 'b', 'c']).str.cat(sep=',')
'a,b,c'
#也可以同时连接复合列表
>>> Series(['a', 'b']).str.cat([['x', 'y'], ['1', '2']], sep=',')
0    a,x,1
1    b,y,2
dtype: object

猜你喜欢

转载自blog.csdn.net/zbrj12345/article/details/81181015
cat