Skip to content
Advertisement

Create multiple new rows per row in data frame

I have the following df:

JavaScript

What I want to do know is add x new rows per row based on the id. So more specific spoken, I want to add a new column containing the date from a range of 7 days and then add a new row with the date for every ID in the df.

so the output should look sth like this if we say I want only dates in the range of 2 days:

JavaScript

I thought of doing is with loops, however this idea seems really slow and not efficient.

JavaScript

I am really thankful for any better idea

Advertisement

Answer

Let us try assign with melt

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