np.where group multiple columns and pivot

37 views Asked by At

I have the following recordset:

ProductType Currency Book
Product_1 USD EPQ001
Product_1 GBP EPQ001
Product_2 USD EPQ001
Product_1 EUR EPQ001
Product_3 ZAR EPQ001
Product_3 USD EPQ001
Product_1 CHF EPQ001
Product_1 USD EPQ001
Product_1 HKD EPQ002
Product_1 HKD EPQ002
Product_1 INR EPQ002

I would like to group the recordset by all three columns, like so:

ProductType Currency Book
Product_1 USD,GBP,EUR,CHF EPQ001
Product_2 USD EPQ001
Product_3 ZAR,USD EPQ001
Product_1 HKD,INR EPQ002

As you can see, groupings occur at all levels and the list of currencies per ProductType / Book categorisation is cast into a string. Duplicates are removed

I've been trying to use the np.where function to group and can successfully group ProductType and Book columns and successfully group the Currency and Book columns, but am lost on how to merge both of the resulting lists so that the Currency appears as a string. Any ideas?

0

There are 0 answers