pandas: mean imputation corrupts Argentina's GDP per capita in the later plot

Aberta Para iniciantes
#658 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
82/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
pandas, python
Domínio
data, documentation

Direção de pesquisa

Comece pela imputação de valores ausentes e pelo cálculo posterior do PIB per capita em lectures/pandas.md; em seguida, reproduza as figuras usando test_pwt.csv de QuantEcon/data-lectures. Decida se deve manter o valor corrompido como uma lição sobre falhas silenciosas ou alterar quais dados são imputados. O trabalho estará concluído quando a aula não apresentar mais como válido o PIB per capita incorreto da Argentina e o gráfico ou a explicação deixar o resultado claro.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

In lectures/pandas.md, the missing value imputation step silently corrupts the GDP per capita figures that the lecture plots later.

What happens

  1. "Let's randomly insert some NaN values" sets df.iloc[idx] = np.nan for idx in zip([0, 3, 5, 6], [3, 4, 6, 2]). The first pair is Argentina's POP.
  2. df = df.fillna(df.iloc[:,2:8].mean()) replaces it with the mean population of the other countries, about 196 million, against Argentina's true 37 million. India and the United States pull the mean far up.
  3. "Standardization and Visualization" then computes GDP percap = total GDP * 1e6 / population from this df and plots it.

Argentina's GDP per capita comes out at about 1,500 instead of 7,900, so the sorted bar chart shows Argentina as poorer than India. Nothing in the output signals that anything went wrong.

country true in lecture
Argentina 7,903 1,504
all other countries unchanged unchanged

(Reproduced against test_pwt.csv in QuantEcon/data-lectures, following the lecture's code.)

The other imputed cells (Israel XRAT, South Africa cc, US year) are not used in the GDP per capita calculation, so only Argentina is affected. Imputing year with a column mean is also odd, but harmless here.

Possible fixes

  • Insert the NaNs only in columns not used later (for example cc and cg), or reload the data before "Standardization and Visualization".
  • Alternatively, keep the bug and turn it into a lesson: point out that the code runs without complaint but gives a wrong answer, because imputation is a modeling choice whose errors flow through to everything computed from it. The course version of this lecture does this in a short "silent failures" section: https://jstac.github.io/py_for_ds_public/working_with_data.html

cc @mmcky

Linguagem predominante
JavaScript
Estrelas
73
Forks
34
Merge médio
28min
PRs com merge (30d)
5

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de QuantEcon/lecture-python-programming

Todas as issues de QuantEcon/lecture-python-programming

Issues semelhantes

Mais issues de JavaScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.