0

I'm just starting out in the world of python programming. I have this database:

INVOICE STOCK_CODE
0015    STIO1
0015    TUY02
0016    BVV01
0017    DFG04
0017    AAA03
0017    STI01

and I would like to be able to transform the dataframe in this way:

INVOICE PROD_1 PROD_2 PROD_3
0015    STI01  TUY02  N/A
0016    BVV01  N/A    N/A
0017    DFG04  AAA03  STI01

For your comments, thank you!

  • Using N columns seems less convenient than a single comma-separate list: `df.groupby("invoice").agg({"stock_code": ",".join})` – J_H Jan 12 '23 at 22:33

0 Answers0