0

I am attempting to sort by the maximum value of a column such as:

    dfWinners = df_new_out['Margin'].apply[max().sort_values(ascending=False)]

But am unsure of how to use the apply function for multiple methods such as max and sort. I'm sure it's a very simple problem but I cannot for the life of me find it through searching on here. Thank you!

4
  • Sorting will give you the max value anyways, so calling sort_values(ascending=False) should be enough. Commented Sep 14, 2017 at 16:06
  • apply with lambda Commented Sep 14, 2017 at 16:06
  • You haven't sufficiently described your problem. Sort what? Do you want to place columns in the order of which column has the largest max for that column? Commented Sep 14, 2017 at 16:10
  • Sorry I should have clarified more. I need to apply the maximum function, and then sort that new maximum functioned column in descending order (If that makes sense) I can clarify more if needed Commented Sep 14, 2017 at 16:21

1 Answer 1

1

It's not clear what you're trying to do by assigning to dfWinners

If you intend dfWinners to be a list of sorted maximum to minimum values as you've described above then you can use the native sorted() method of python.

dfWinners = sorted(df_new_out['Margin'])

Else, you can sort your dataframe in place

df_new_out.sort_values(by = ['Margin'], ascending=False, inplace=True)
Sign up to request clarification or add additional context in comments.

2 Comments

Not really necessary I guess, could use the second option. My problem is I'm getting errors as such: Cannot access callable attribute 'sort_values' of 'SeriesGroupBy' objects, try using the 'apply' method
@andrewfay Sorry, edited. the columns are parameters

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.