title: Find max by year and return date on which max occurred in Pandas with dates as index
body: <p>I have this dataframe</p>
  <pre><code>date,AA
  1980-01-01, 77.7
  1980-01-02, 86
  1980-01-03, 92.3
  1980-01-04, 96.4
  1980-01-05, 85.7
  1980-01-06, 75.7
  1980-01-07, 86.8
  1980-01-08, 93.2
  1985-08-13, 224.6
  1985-08-14, 213.9
  1985-08-15, 205.7
  1985-08-16, 207.3
  1985-08-17, 202.1
  </code></pre>
  <p>I would like to compute the max for each year and the date where it happens. I am struggling because I would like to keep indeed the date as index.</p>
  <p>Indeed I read it as:</p>
  <pre><code>dfr    = pd.read_csv(fnamed, sep=',', header = 0, index_col=0, parse_dates=True)
  </code></pre>
  <p>I know that I could resample as</p>
  <pre><code>dfr_D = dfr.resample('Y').max()
  </code></pre>
  <p>but in this case I would lose the information about the location of the maximum value within the year.</p>
  <p>I have found this:</p>
  <pre><code>idx = dfr.groupby(lambda x: dfr['date'][x].year)[&quot;A&quot;].idxmax()
  </code></pre>
  <p>However, dfr['date'] seems to be the name of the column while in my case date in an index and '.year' is not one of its properties.</p>
  <p>I have the felling that I should work with &quot;groupby&quot; and &quot;indexmax&quot;. However, all the attends that I made, they all failed.</p>
  <p>Thanks in advance</p>