When filling an array with values from a shorter array in R, R will "recycle" the elements in the shorter array. For example, setting an array of length 7 [ , , , , , , ]
with the array ['a','b','c']
will give ['a','b','c','a','b','c','a']
.
Is there a built-in method to fill a pandas column (or numpy array) using a similar style of recycling?
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With