0

Suppose I have a dataframe like this:

df =pd.DataFrame({'date': ['01-01-2022', '02-01-2022', '01-01-2022', '02-01-2022'],
    'company': ['x', 'x', 'y', 'y'],
    'sales': [ 100,200,300,400]})

df.set_index('date', inplace = True)


        company sales
date        
01-01-2022  x   100
02-01-2022  x   200
01-01-2022  y   300
02-01-2022  y   400

I would like to transform this dataframe where the unique company names are the new column names and the sales the values per name. The end result should look like this:

enter image description here

Thanks for your help!

Jaap
  • 55
  • 1
  • 2
  • 5

0 Answers0