目次
概要
Series.repeat で各要素を指定回数だけ繰り返した Series を作成する方法について解説します。
pandas.Series.repeat
pandas.Series.repeat() は、Series の各要素を指定回数だけ繰り返した Series を作成して返します。
引数
名前 | 型 | デフォルト値 |
---|---|---|
repeats | int or array of ints | |
繰り返す回数 |
返り値
名前 | 説明 |
---|---|
Series | Newly created Series with repeated elements. |
int を指定した場合、すべての要素をその回数だけ繰り返します。
In [1]:
0 1 0 1 1 2 1 2 2 3 2 3 dtype: int64
各要素ごとに繰り返す回数を変更する場合、Series と同じ長さの int の配列を指定します。
In [2]:
0 1 1 2 1 2 2 3 2 3 2 3 dtype: int64
コメント