daveskis
daveskis

Reputation: 153

Python pandas - Index lookup based on criteria

I have an extract of a dataframe below:


              IndexR  ATOI_INDEX  pf_52w_rolling_R  atoi_52w_rolling_R
date                                                                  
2012-07-27  3.576907    1.384371         -0.208960           -0.038279
2012-08-03  3.563627    1.388237         -0.129268            0.039078
2012-08-10  3.598886    1.404311         -0.118584            0.032610
2012-08-17  3.731085    1.433466         -0.048716            0.072498
2012-08-24  3.727810    1.426206         -0.053756            0.043906
2012-08-31  3.588335    1.417722         -0.092489            0.026757
2012-09-07  3.613275    1.419281         -0.081376            0.040861
2012-09-14  3.746451    1.438596          0.006892            0.066220
2012-09-21  3.834664    1.445147          0.163057            0.136574
2012-09-28  3.785910    1.438789          0.138433            0.099768
2012-10-05  3.899735    1.473921          0.084421            0.086089
2012-10-12  3.896683    1.472302          0.070044            0.073716
2012-10-19  4.040653    1.499956          0.142053            0.110457
2012-10-26  3.934642    1.468487          0.063541            0.034418
2012-11-02  3.939487    1.464218          0.094581            0.048841
2012-11-09  3.953680    1.464842          0.068256            0.046199
2012-11-16  3.802839    1.424206          0.080771            0.045743
2012-11-23  3.874423    1.449342          0.178798            0.115653
2012-11-30  3.976766    1.480888          0.115446            0.058999
2012-12-07  3.974976    1.497452          0.113870            0.092148

I need to print the date in which the minimum value of the pf_52w_rolling_R occurred.

I've tried a number of possibilities, but I keep getting type errors (TypeError: cannot do index indexing on <class 'pandas.core.indexes.datetimes.DatetimeIndex'> with these indexers [-0.208960] of <class 'float'>

The latest attempt is below:

rolling.loc[rolling['pf_52w_rolling_R'].min()]

Upvotes: 0

Views: 28

Answers (1)

BENY
BENY

Reputation: 323316

Let us try idxmim which will return the min value index

rolling.loc[rolling['pf_52w_rolling_R'].idxmin()]

Upvotes: 2

Related Questions