title: How to calculate mean in a dataframe pandas for a single year?
body: <p>everyone. I tried this method <a href="https://stackoverflow.com/questions/72434857/can-i-use-a-specific-element-inside-the-groupby-functions-instead-of-using-colum">Can I use a specific element inside the groupby functions instead of using column name?</a></p>
  <p>but i gor error.</p>
  <p>So I need to calculate the population mean next to the 'Hispanic or Latino label within this dataframe. How do I select exactly the population values for &quot;Hispanic or Latino&quot; and calculate the mean for them?</p>
  <pre><code>kind_of_pop_df = pd.DataFrame(data=pop_list_us, columns=[&quot;Year&quot;, &quot;Ethnicity&quot;, &quot;Hispanic Population&quot;])
  kind_of_pop_df.head(7)
  kind_of_pop_df.set_index(&quot;Year&quot;,inplace=True)
  print(kind_of_pop_df)
  
                     Ethnicity  Hispanic Population
  Year                                             
  2019  Not Hispanic or Latino             10710524
  2019      Hispanic or Latino              1583156
  2019  Not Hispanic or Latino              2763709
  2019      Hispanic or Latino               320595
  2019  Not Hispanic or Latino                42268
  ...                      ...                  ...
  2013      Hispanic or Latino                 2791
  2013  Not Hispanic or Latino               105872
  2013      Hispanic or Latino              1567526
  2013  Not Hispanic or Latino               323451
  2013      Hispanic or Latino               241243
  
  [98 rows x 2 columns]
  </code></pre>
  <p>Can you answer with specific answers? Thanks!</p>