0

Good afternoon.

I have a dataframe:

Date          Name     Count
10/1/2022     Mike      10
10/1/2022     Jen       15 
10/1/2022     Carol     25
10/2/2022     Mike      7
10/2/2022     Jen       13
10/2/2022     Carol     30 

I need to edit it to the following df:

          10/1/2022   10/2/2022
Mike       10            7
Jen        15            13
Carol      25            30 

I tried different grouping and fail Will highly appreciate help

RJ Adriaansen
  • 9,131
  • 2
  • 12
  • 26
Mike L
  • 47
  • 3
  • Please provide enough code so others can better understand or reproduce the problem. – Community Oct 24 '22 at 19:55
  • Does this answer your question? [How can I pivot a dataframe?](https://stackoverflow.com/questions/47152691/how-can-i-pivot-a-dataframe) – Naveed Oct 24 '22 at 21:17

1 Answers1

1

Try pivot instead of groupby

df.pivot(index="Name", columns="Date", values="Count")

Date   10/1/2022  10/2/2022
Name                       
Carol         25         30
Jen           15         13
Mike          10          7

EDIT: add .sort_values("10/1/2022") to get the example

bitflip
  • 3,436
  • 1
  • 3
  • 22