'Outputing a sortable list from a pandas dataframe
I need the top 10 products sorted by total sales from a pandas dataframe. I can output a list with all the values and product name but cannot find a way of outputting a list of sorted values. I have tried creating lists, tuples and dictionaries but I keep getting an error that these cannot be sorted.
petproducts = df_cleaned['prod_title'].unique()
for x in petproducts:
totaltoys =df_cleaned.loc[df_cleaned['prod_title'] == x, 'total_sales'].sum()
print (x,totaltoys)
This gives me a series on pairs which I need to make into something where I can extract the top 10 products.I am a beginner I have been working on this for days.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
