1

I am on a code in python and I would like to transform this dataFrame :

Before:

enter image description here

Into this DataFrame :

enter image description here

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...

1
  • 2
    please show the code instead of pictures for input and desired output Commented Apr 12, 2017 at 15:46

1 Answer 1

2

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')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.