Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating an ordinal list

Status
Not open for further replies.

Pegasus101

IS-IT--Management
Aug 1, 2014
8
GB
Thank you in advance for your help.

There is a products table in a csv that has multiple products. I need to create an ordinal list of the ranking of the products in descending order, so that a list is created with the ranking of the products most sold.

I thought that using the dictionary comprehensions are te way to go, but couldn't get further than the code below, which creates a list of the products alphabetically but doesnt list rank them as the products most sold.

Code:
labels = df['PRODUCT_NAME'].astype('category').cat.categories.tolist()
replace_map_comp = {'PRODUCT_NAME' : {k: v for k,v in zip(labels,list(range(1,len(labels)+1)))}}

print(replace_map_comp)

Many thanks and let me know if you need more information.
 
Could you give an example of the data you are putting in (10 rows will do) and the order you expect to get?
 
Would really want to see the kind of data that you put in, so can you share some? And what kind of order is needed?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top