1

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?

1 Answer 1

1

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)))
Sign up to request clarification or add additional context in comments.

1 Comment

@roastbeeef yw~ : -) happy coding

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.