0

I have a similar dataframe to the next one:

Names Case type Number
Patrick Email 10
James Phone 78
Kerstin Email 50
James Email 69
Patrick Phone 48
Kerstin Phone 42

My idea is to expand Case type into another column so that each agent has email and phone assigned to their names and it only appears one:

Names Type 1 Number Type 2 Number
Kerstin Email 50 Phone 42
James Email 69 Phone 78
Patrick Email 10 Phone 48

So far, I have tried using .groupby('Names') but this does not seem to work at all.

Is there anything that can be done? Another idea I had was to sort things by name and then split the dataframe into two dataframe and then merge them by agent? But it seems like there's something that could work better.

Thanks!

Harr1ls
  • 71
  • 5

1 Answers1

2

Maybe, this could be a better representation?

>>> df.pivot(index='Names', columns='Case type', values='Number')

Case type  Email  Phone
Names
James         69     78
Kerstin       50     42
Patrick       10     48

In your idea, you can't distinguish email Number from phone.

Corralien
  • 109,409
  • 8
  • 28
  • 52