Вычисление среднего значения конкретной строки с помощью loc, loc не находит значение строки ⇐ Python
Вычисление среднего значения конкретной строки с помощью loc, loc не находит значение строки
I'm new to Python and stackoverflow. So please forgive any shortcomings in my posting. I want to calculate the row average of a specific row(e.g. Bahrain) and I'm having problem achieving it. I used df.loc but It's returning a key error with the name of the country as it doesn't recognize the name. My dataframe look like something like this:
Country 1990 1995 2000 2005 2010 2015 0 Bahrain 5 4 3 2 1 5 1 Maldives 10 9 8 7 6 5 2 Germany 7 4 3 2 1 7 . .... .. .. .. .. .. .. . .... .. .. .. .. .. .. . .... .. .. .. .. .. .. I wrote this and I get an error.I got a key error with the name of row.
mean=df.loc['Bahrain'].mean(axis=1) I am getting the following error:
The error
I prefer to have an output in format of numpy.float64.
Источник: https://stackoverflow.com/questions/780 ... -the-row-v
I'm new to Python and stackoverflow. So please forgive any shortcomings in my posting. I want to calculate the row average of a specific row(e.g. Bahrain) and I'm having problem achieving it. I used df.loc but It's returning a key error with the name of the country as it doesn't recognize the name. My dataframe look like something like this:
Country 1990 1995 2000 2005 2010 2015 0 Bahrain 5 4 3 2 1 5 1 Maldives 10 9 8 7 6 5 2 Germany 7 4 3 2 1 7 . .... .. .. .. .. .. .. . .... .. .. .. .. .. .. . .... .. .. .. .. .. .. I wrote this and I get an error.I got a key error with the name of row.
mean=df.loc['Bahrain'].mean(axis=1) I am getting the following error:
The error
I prefer to have an output in format of numpy.float64.
Источник: https://stackoverflow.com/questions/780 ... -the-row-v
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Вычисление среднего значения движущейся площади с отсутствующим значением над морем
Anonymous » » в форуме Python - 0 Ответы
- 17 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Использование пандов для расчета среднего декабрьского января-февраля среднего
Anonymous » » в форуме Python - 0 Ответы
- 5 Просмотры
-
Последнее сообщение Anonymous
-