0

Suppose I have list

a = ["0-3","4-7","8-11","12-15","16-19","20-23"]

I want to repeat all elements in the list for a new column in a dataframe which has 1000 rows. How to do that in pandas?

theletz
  • 1,713
  • 2
  • 16
  • 22
Chethan
  • 611
  • 3
  • 11
  • 4
    Please read [this](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) on how to post a good reproducible question. – Ukrainian-serge Mar 05 '20 at 04:55

1 Answers1

2

EDITED:

Please refer to my comment, but if I understand you correctly you need:

import pandas as pd

a_list = (["0-3","4-7","8-11","12-15","16-19","20-23"]*167)[:1000]

series = pd.Series(a_list)

print(series)

0        0-3
1        4-7
2       8-11
3      12-15
4      16-19
       ...
995    20-23
996      0-3
997      4-7
998     8-11
999    12-15
Length: 1000, dtype: object
Ukrainian-serge
  • 854
  • 7
  • 12
  • 1
    `pd.Series` also has a [`repeat`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.repeat.html) func – anky Mar 05 '20 at 05:18
  • Thanks. here each element is repeating 167 times then next element. I want to all 6 the elements from 0 to 5th row then repeat whole list. Is this possible? – Chethan Mar 05 '20 at 05:21