1

I am trying to get the index of the row that has the maximum value in the column '% Renewable'. This is the dataframe:

df = pd.DataFrame({'% Renewable': [np.NaN, 12, np.NaN, 11, 17, 62, 18, 15, np.NaN, 2, np.NaN, np.NaN, 6, np.NaN, 70]},
   index=['China', 'United States', 'Japan', 'United Kingdom', 'Russian Federation', 'Canada', 'Germany', 'India', 'France', 'South Korea', 'Italy', 'Spain', 'Iran', 'Australia', 'Brazil'])

I get the maximum value using the max method:

 df[['% Renewable']].max()

'70' is the maximum value and it is associated to the index key 'Brazil'. But which command line does return 'Brazil'? My try:

df[df['% Renewable'] == float(70)].index.tolist()

Unfortunately, I get an empty list. Any idea?

Antonio Serrano
  • 882
  • 2
  • 14
  • 27

0 Answers0