2

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

1 Answer 1

3

Please try below code

output= df.sort_values(by=['items'])['items'].drop_duplicates().tolist()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.