I have a pandas dataframe
on which I did a groupby
and value_counts
:
df4.groupby(['City'])['User Type'].value_counts()
This gives me following output:
City User Type
C Subscriber 238889
Customer 61110
Dependent 1
N Subscriber 269149
Customer 30159
W Subscriber 220786
Customer 79214
Now I did df6=df5.unstack(level=1).reset_index()
this returned a df like shown below:
Now i did df6.set_index('City',inplace=True)
This produces output:
I am unable to understand why city is shown under "User Type" and is there a way to remove "User Type" index name
After doing:
df6=df5.unstack(level=1).reset_index().rename_axis(None, axis=1)
and then doing : df6.set_index('City',inplace=True)
it still shows city on different level: