title: How to select values based on array's index from relative index within pandas groups
body: <p>I have a DataFrame, which is already sorted by the columns <code>('year', 'month')</code>, that looks like this:</p>
  <pre><code>df = pd.DataFrame({
      'year': [2020, 2020, 2020, 2021, 2021, 2021, 2021],
      'month': [1, 2, 5, 2, 4, 7, 9],
      'values': [
          ['a', 'b', 'c'], ['a', 'b', 'c'], ['a', 'b', 'c'],
          ['A', 'B', 'C', 'D'], ['A', 'B', 'C', 'D'], ['A', 'B', 'C', 'D'], ['A', 'B', 'C', 'D']
      ]
  })
  
  print(df)
  
      year    month   values
  0   2020    1       ['a', 'b', 'c']
  1   2020    2       ['a', 'b', 'c']
  2   2020    5       ['a', 'b', 'c']
  3   2021    2       ['A', 'B', 'C', 'D']
  4   2021    4       ['A', 'B', 'C', 'D']
  5   2021    7       ['A', 'B', 'C', 'D']
  6   2021    9       ['A', 'B', 'C', 'D']
  </code></pre>
  <p>I want to create a new column named <code>'value'</code>, which contains the value of the <em>i-th</em> element on the <code>'values'</code> array, where <em>i</em> is the index of the corresponding month, grouped by year. In this case, the outcome would be:</p>
  <pre><code>    year    month   values                  value
  0   2020    1       ['a', 'b', 'c']         'a'
  1   2020    2       ['a', 'b', 'c']         'b'
  2   2020    5       ['a', 'b', 'c']         'c'
  3   2021    2       ['A', 'B', 'C', 'D']    'A'
  4   2021    4       ['A', 'B', 'C', 'D']    'B'
  5   2021    7       ['A', 'B', 'C', 'D']    'C'
  6   2021    9       ['A', 'B', 'C', 'D']    'D'
  
  </code></pre>
  <p>I'm assuming there is no data missing on the arrays. Some lines I've tried involve using <code>.groupby('year')</code> followed by <code>.get_loc('month')</code>, but couldn't get the correct result so far.</p>
  <p>EDIT:</p>
  <p>There is one detail I forgot to mention: The months are not necessarily in a uniform range, therefore the index is not always <code>month-1</code>. I've edited the DataFrame in question to reflect this nuance.</p>