pandas.Index.repeat#
- Index.repeat(repeats, axis=None)[源代码]#
重复索引的元素。
返回一个新的Index,其中当前Index的每个元素连续重复给定次数。
- 参数
- repeats整型或整型数组
每个元素的重复次数。这应该是一个非负整数。重复0次将返回空索引。
- axis无
一定是
None
。没有效果,但由于与NumPy兼容而被接受。
- 退货
- repeated_index索引
新创建的包含重复元素的索引。
参见
Series.repeat
级数的等价函数。
numpy.repeat
类似的方法
numpy.ndarray
。
示例
>>> idx = pd.Index(['a', 'b', 'c']) >>> idx Index(['a', 'b', 'c'], dtype='object') >>> idx.repeat(2) Index(['a', 'a', 'b', 'b', 'c', 'c'], dtype='object') >>> idx.repeat([1, 2, 3]) Index(['a', 'b', 'b', 'c', 'c', 'c'], dtype='object')