I am working with data that contains multiple UNSPSC codes each with a different Price. I want to get a pivot table that combines all of the prices per UNSPSC code.
Ultimately, I want to extract the top 5 UNSPSCs by their highest price.
UNSPSC= pivot_table(analysis, rows=['UNSPSC'], cols =['Extended Price'])
This definitely doesn't work. I don't want all of the columns it provides. I just want two. UNSPSC and then the aggregate price associate with the unique code.
<class 'pandas.core.frame.DataFrame'>
Index: 78 entries, 12142100.0 to 55121611.0
Columns: 21924 entries, ($ Difference, 2.70000004768) to (Quantity, 3255.19995117)
dtypes: float64(21924)
I also tried to pivot by
UNSPSC =analysis.pivot(index = 'UNSPSC', columns ='Extended Price')
My error was ReshapeError: Index contains duplicate entries, cannot reshape
I tried to utilize groupby and aggfun=np.sum but I can't seem to get what I am looking for. How can I get a pivot table with that shows the sum of the prices to each unique UNSPSC?
Thanks!