6

I have the following dataframe:

      Q        GDP  
248 2008q3  14891.6 
249 2008q4  14577.0 
250 2009q1  14375.0 
251 2009q2  14355.6 

I want to the value for Q where GDP is lowest.

Based on this post,extract column value based on another column pandas dataframe, I tried the following:

    df = df.loc[df['GDP'].min(),'Quarters'].iloc[0]

However I got this following error msg:

    TypeError: cannot do label indexing on <class 'pandas.indexes.range.RangeIndex'> with these indexers [14355.6] of <class 'numpy.float64'>

Any help would be much appreciated!

user2629628
  • 161
  • 1
  • 3
  • 11

1 Answers1

11

This:

df.loc[df['GDP'].idxmin()]['Q']

Output:

'2009q2'
Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58