0

Given the following output with the groupby demand

created_at  sentiment
2021-04-19  NEGATIVE      20
            POSITIVE       7
2021-04-20  NEGATIVE     104
            POSITIVE      70
2021-04-21  NEGATIVE      64
            POSITIVE      53
2021-04-22  NEGATIVE     115
            POSITIVE      50

I want to get a new dataframe with the columns

'created_at', 'positive', 'negative',
2021-04-19     7           20       
2021-04-20     70          104

and so on.

I am thankful for all your answers.

Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91
Merlin
  • 1

1 Answers1

0

You seem to be wanting to pivot_table():

output = df.reset_index().pivot_table(index='created_at',columns='sentiment',values='name_of_the_series')
Celius Stingher
  • 17,835
  • 6
  • 23
  • 53