pandas.Series.str.repeat#
- Series.str.repeat(repeats)[源代码]#
在 Series 或 Index 中重复每个字符串。
- 参数:
- 重复int 或 int 序列
所有相同的值(整数)或每个不同的值(序列)。
- 返回:
- Series 或 pandas.Index
由输入参数 repeats 指定的重复字符串对象的序列或索引。
参见
Series.str.lowerConvert all characters in each string to lowercase.
Series.str.upperConvert all characters in each string to uppercase.
Series.str.titleConvert each string to title case (capitalizing the first letter of each word).
Series.str.stripRemove leading and trailing whitespace from each string.
Series.str.replaceReplace occurrences of a substring with another substring in each string.
Series.str.ljustLeft-justify each string in the Series/Index by padding with a specified character.
Series.str.rjustRight-justify each string in the Series/Index by padding with a specified character.
例子
>>> s = pd.Series(["a", "b", "c"]) >>> s 0 a 1 b 2 c dtype: object
单个整数在系列中重复字符串
>>> s.str.repeat(repeats=2) 0 aa 1 bb 2 cc dtype: object
在序列中,整数的重复对应于序列中的字符串
>>> s.str.repeat(repeats=[1, 2, 3]) 0 a 1 bb 2 ccc dtype: object