python - Pandas dataframe, max of selection -


i have pandas dataframe following columns:

i need write function, takes df data , returns string country, gdp maximum among countries area(sq km) less 200 or population less 1000.

how write code correctly?

def find_country(df):     df.loc[((df.area < 200).max(df.gdp))|(df.population < 1000)] 

first of should make first column index. done using following command:

df.set_index('country', inlace = true) 

assuming want replace dataframe reworked version. find desired country date has maximum gdp, instance, , return index. subscript of index needed actual value of index.

def find_country(df):     return df[df['gdp'] == max(df['gdp'])].index[0] 

i hope help, fabian


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -