pandas.Series.str.repeat#

Series.str.repeat(repeats)[源代码]#

重复 Series 或 Index 中的每个字符串。

Parameters:
repeatsint 或 int 序列

对所有字符使用相同的值(int)或对每个字符使用不同值(序列)。

Returns:
Series 或 pandas.Index

由输入参数 repeats 指定的重复字符串对象的 Series 或 Index。

Examples

>>> s = pd.Series(['a', 'b', 'c'])
>>> s
0    a
1    b
2    c
dtype: object

单个 int 重复 Series 中的字符串

>>> s.str.repeat(repeats=2)
0    aa
1    bb
2    cc
dtype: object

int 序列重复 Series 中相应的字符串

>>> s.str.repeat(repeats=[1, 2, 3])
0      a
1     bb
2    ccc
dtype: object