0

I have a sample data from a very large data set. Is there a code that could turn the below table into the output table

What I would like to achieve is, a way to find how many times a company names occurs (eg A 3 times) and to suffix each occurance into an index for that company. Then to flip the rows and columns as shown below.

Input table =

company revenue
A 10
A 20
A 30
B 10
B 15

Output table =

A_1 A_2 A_3 B_1 B_2
revenue 10 20 30 10 15
userr161
  • 1
  • 1
  • Note that if you expect a single row in the output, you don't even need a pivot: `df.assign(company=df['company']+df.groupby('company').cumcount().add(1).astype(str)).set_index('company').T` – mozway Sep 07 '22 at 15:50

0 Answers0