Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

numpy dataframe get maximum difference in a single column

I want to get the biggest temperature chanche in a dataframe of countries.

My first Idea was to make groups df.groupby(‘country_code’)[‘temperature’].max(), df.groupby(‘country_code’)[‘temperature’].min(), subtract them and get the maximum. I guess there is a better way to to that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here’s a slightly different approach, dealing with only one set of groups

def temp_range(group):
    return group.max() - group.min()

df.groupby('country_code')['temperature'].apply(temp_range)

Not sure if it’s better though

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading