0

Given that I have the following Pandas DataFrame: df =

Lttr Day Color Num
A Mon Red One
A Tue Blu One
A Wed Grn One
A Wed Grn Two

How could I best go about re-arranging it to something like:

Lttr Mon Tue Wed
A Red Blu Grn

1 Answers1

1

Use:

(df.pivot_table(index='Lttr', columns='Day', values='Color', aggfunc='first')
   .reset_index()
   .rename_axis(columns=None)
 )

Output:

  Lttr  Mon  Tue  Wed
0    A  Red  Blu  Grn
mozway
  • 194,879
  • 13
  • 39
  • 75