Reputation: 111
I want to write a program to return names in a list based on the number of reports in descending order. like ['Jack', 'Joe', 'Rick'....]
df=
Number_of_reports Name
5 Rick
4 Amanda
7 Joe
8 Jack
2 Ryan
mylist=[]
greater_value=0
for i in df['Number_of_Reports']:
if greater_value > i:
mylist.append(df['Name'])
Any help will be greatly appreciated
Upvotes: 0
Views: 91
Reputation: 6543
You can use sort_values
and to_list
:
names = df.sort_values(by='Number_of_reports', ascending=False)['Name'].tolist()
Which gives:
['Jack', 'Joe', 'Rick', 'Amanda', 'Ryan']
Upvotes: 3