Skip to content
Advertisement

How do I append a repeating list to a dataframe?

I have a list sub = ["A","B","C","D","E","F"] and a dataframe of the following format:

enter image description here

I need to write a code for my dataframe to finally look like the following format:

enter image description here

Advertisement

Answer

You can create a cycle using itertools.cycle, and cut it to the appropriate length using itertools.islice.

JavaScript

So, in your case, you can just cut it to the length of the dataframe and assign it as a new column:

JavaScript

which gives:

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