I have this dataframe:
np.random.seed(0)
df = pd.DataFrame({"Status": np.random.choice(["Married", "Single", "Single", "Single", "Widow"], 10000),
"Genre": np.random.choice(["Masculine", "Masculine", "Masculine", "Femenine"], 10000),
"Count": 1}).groupby(["Status", "Genre"]).agg("sum").reset_index()
df
Status Genre Count
0 Married Femenine 485
1 Married Masculine 1520
2 Single Femenine 1493
3 Single Masculine 4552
4 Widow Femenine 520
5 Widow Masculine 1430
I'm looking to change it where the columns are the Genre
values, and an index with the Status
values, like:
Single Married Widow
Masculine 4552 1520 1430
Femenine 1493 485 520
I have tried with a mix of melt()
and .T
, but still isn't working. I'm looking for a general approach, as I have 5 Genre
values and 20 Status
values.