With a dataframe like this:
date user sales_blue sales_red calls_blue calls_red
2019/06/01 A 30 50 3 4
2019/06/01 B 60 70 1 2
2019/06/02 A 25 35 4 6
2019/06/02 B 42 52 5 7
I'm trying to get to the following:
date user color sales calls
2019/06/01 A blue 30 3
2019/06/01 A red 50 4
2019/06/01 B blue 60 1
2019/06/01 B red 70 2
2019/06/02 A blue 25 4
2019/06/02 A red 35 6
2019/06/02 B blue 42 5
2019/06/02 B red 52 7
Pandas' documentation on melt
is quite explicit when only one variable needs to be unpivoted, but I'm having a hard time understanding what to do for this case, where multiple variables are to be unpivoted (here, sales
and calls
).