Skip to content
Advertisement

how to spead a list and put into a new column based on number of rows

lets say I have a brand of list:

JavaScript

and I want this list to repeteadly fill a new column called category as much as my rows have.

I want the first row have 'a', the second row have 'b', and the third row have 'ab', and the cycle repeats until the last rows like the example below:

JavaScript

What I have tried so far is:

JavaScript

but I got this kind of error

JavaScript

how should I fix my script in order to get the desired results?

thanks.

Advertisement

Answer

Use numpy.tile by repeat with integer division for number of repeats:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement