My dataframe looks like this.
It's the result of this code:
survival_by_position = survival_by_position.groupby("POSITION")["SURVIVED"].value_counts().rename("Count").reset_index()
survival_by_position = survival_by_position.pivot(index = "POSITION", columns = "SURVIVED", values = "Count")
survival_by_position = survival_by_position.rename(columns = {False: "DEAD", True: "SURVIVORS"})
I want it to look like this.
That is, POSITION should remain the index, but the columns DEAD and SURVIVORS should "come down", and SURVIVED should disappear. I've tried to (re)set the index, create a new dataframe and assign it the right index and columns, nothing worked. I either get all NaNs, or the default integer index, or some error. I know this has got to be some multi-index trickery, but I am not familiar with that so I don't know how to fix it.