With this dataframe:
+--------+---------+------+----------+
| metric | control | test | duration |
+--------+---------+------+----------+
| logins | 4 | 2 | short |
+--------+---------+------+----------+
I want to transpose the control
and test
column values into multiple rows under their own column called value
, but I also want to consolidate the control
and test
columns into one column called cohort
. The result would then be:
+--------+---------+-------+----------+
| metric | cohort | value | duration |
+--------+---------+-------+----------+
| logins | control | 4 | short |
+--------+---------+-------+----------+
| logins | test | 2 | short |
+--------+---------+-------+----------+
I know this involves a melt or pivot function, but I can't figure out how to do it.