0

i have this kind of problem.

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 "Hispanic or Latino" and calculate the mean for them?

kind_of_pop_df = pd.DataFrame(data=pop_list_us, columns=["Year", "Ethnicity", "Hispanic Population"])
kind_of_pop_df.head(7)
kind_of_pop_df.set_index("Year",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]
  • check [this](https://stackoverflow.com/questions/72434857/can-i-use-a-specific-element-inside-the-groupby-functions-instead-of-using-colum) solution - only change `mean` instead `sum` – jezrael May 30 '22 at 13:42

0 Answers0