roastbeeef
roastbeeef

Reputation: 1119

Creation of pandas dataframe, repeating entries with loop

I'm trying to pad out a dataframe that I'm using to graph some sales data to fill the remaining weeks of the year with zeros. My code is as follows:

weeks = [x for x in range(max(sales['WEEK']+1),53)]
padding = pd.DataFrame(np.zeros((53max(sales['WEEK']+1),len(sales.columns))),index=weeks)

Which returns me a pandas DataFrame 43 rows x 3 columns. What I really need to do is repeat the index of each of my 43 rows 7 times, giving me a DataFrame with 301 rows . I can't work this out, any ideas?

Upvotes: 1

Views: 30

Answers (1)

BENY
BENY

Reputation: 323226

Assuming you have the df as you dataframe with shape (43,3)

With repeat+reindex

New_df=df.reindex(df.index.repeat([7]*len(df)))

Upvotes: 1

Related Questions