pandas.Index.repeat #
- 指数。重复(重复,轴=无) [来源] #
重复索引的元素。
返回一个新索引,其中当前索引的每个元素连续重复给定的次数。
- 参数:
- 重复int 或 int 数组
每个元素的重复次数。这应该是一个非负整数。重复 0 次将返回空索引。
- 轴无
必须是
None
。没有效果,但由于与 numpy 兼容而被接受。
- 返回:
- 指数
新创建的索引包含重复元素。
也可以看看
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')