Recycling in Pandas Dataframe
With numpy.resize
-
In [199]: a = ['a','b','c']In [200]: np.resize(a,7)Out[200]: array(['a', 'b', 'c', 'a', 'b', 'c', 'a'], dtype='|S1')
Kinda, but it isn't as straightforward as it is in R.
from itertools import cycle, islicecyc = cycle(['a','b','c'])pd.Series(list(islice(cyc, 0, 7)))0 a1 b2 c3 a4 b5 c6 adtype: object
First, create an infinite iterator using itertools.cycle
. Then, slice out a portion of this infinite iterator to retrieve just the number of elements you want, using itertools.islice
.
Change 7
to as small or as large as you want your Series to be.