Pandas Dataframe column to python list

Viewed 43

I have a Pandas data frame with duplicate values and I want to convert into python list in alphabetical order.

print(df)
            items
0           Shoes
1           Shoes
2           Jacket
3           Basket
4           Shoes
5           Umbrella
6           Basket
7           Jacket
output=['Basket','Jacket','Shoes','Umbrella']
1 Answers

Please try below code

output= df.sort_values(by=['items'])['items'].drop_duplicates().tolist()
Related