python - Pandas dataframe, max of selection -
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
Post a Comment