Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a column of repeating values to dataframe

I have some quarter level data for finance deals, so a pretty big dataset. I now want to add the following values to a new column repeated over and over:

[-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12]

The column should then look something like this:

A
-12
-11
-10
...
11
12
-12
-11
...
11
12

So basically just that list repeating over and over until the last row of my Dataframe. I hope this question is clear enough.

like image 218
Elias K. Avatar asked Dec 02 '25 00:12

Elias K.


1 Answers

Try this:

N = len(df)
df['A'] = pd.Series(np.tile(lst, N//len(lst))).iloc[:N]
like image 91
MaxU - stop WAR against UA Avatar answered Dec 03 '25 14:12

MaxU - stop WAR against UA



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!