0

I have a dataframe like this:

   name    course   score
0  jhin      math     100
1  jhin   physics      90
2  jhin   chinese      95
3  lisa      math     100
4  lisa   physics      90
5  lisa   chinese      95

What I want is like this:

   name   math   physics   chinese
0  jhin    100        90        95
1  lisa    100        90        95

This is a demonstration of what I want to do, what's more, I want to fill empty cells of columns math, physics and chinese with certain value, such as None

Any help would be greatly appreciated ;-)

Jhin Koo
  • 22
  • 3
  • there must be a solution already but my English is quite poor and I don't know how to describe it precisely in Google to retrieve an answer ;-( – Jhin Koo Jan 18 '22 at 07:56
  • `df.groupby(['name', 'course'])['score'].first().unstack()` – timgeb Jan 18 '22 at 08:01

0 Answers0