I have a dataframe like so:
df = pd.DataFrame(
[
["True", "False"],
["True", "True"],
["False", "True"],
],
index=["bob", "sue", "joe"],
columns=["R1", "R2"],
)
I'd like to melt the df so that the index names are used, and replace the Trues with the column name, so the output is like so:
df = pd.DataFrame(
[
["bob", "R1"],
["sue", "R1"],
["sue", "R2"],
["joe", "R2"],
],
columns=["Names", "Role"],
)
How can I achieve this?