Reputation: 23
I am on a code in python and I would like to transform this dataFrame :
Before:
Into this DataFrame :
I tried to pivot the table with the command :
pd.pivot_table(mytable, index = [JAN, FEB, MAR])
But I am not satisfied by the result...
Upvotes: 1
Views: 69
Reputation: 27899
This should work:
df = pd.melt(df, id_vars=['Word'], value_vars=['JAN', 'FEB', 'MAR']).dropna()
df = df.pivot(index='variable', columns='value', values='Word')
Upvotes: 2