I have a dataframe, where I want to duplicate rows N times, where N is a value in another row.
For example, if this is my dataframe:
Company WEEK_DAYS SEPTEMBER 15 SEPTEMBER 22 SEPTEMBER 29 value
0 google MON-FRI 0 0 5 0.5
1 google TUE 3 2 0 0.7
so, the columns I want to replicate based on their value are SEPTEMBER 15, SEPTEMBER 22, and SEPTEMBER 29, and the value should be value.
So the final output should be something like that:
Company WEEK_DAYS WEEK value
0 google MON-FRI SEPTEMBER 29 0.5
1 google MON-FRI SEPTEMBER 29 0.5
2 google MON-FRI SEPTEMBER 29 0.5
3 google MON-FRI SEPTEMBER 29 0.5
4 google MON-FRI SEPTEMBER 29 0.5
5 google TUE SEPTEMBER 15 0.7
6 google TUE SEPTEMBER 15 0.7
7 google TUE SEPTEMBER 15 0.7
8 google TUE SEPTEMBER 22 0.7
9 google TUE SEPTEMBER 22 0.7
I tried using stack and pivot - but I didn't manage to get the desired output.
Any help will be appreciated!