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

Offen Anfängerfreundlich
#658 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
82/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
pandas, python
Bereich
data, documentation

Rechercherichtung

Beginne mit der Imputation fehlender Werte und der späteren Berechnung des BIP pro Kopf in lectures/pandas.md und reproduziere anschließend die Abbildungen mit test_pwt.csv aus QuantEcon/data-lectures. Entscheide, ob der beschädigte Wert als Lektion über unbemerkte Fehler beibehalten oder geändert werden soll, welche Daten imputiert werden. Die Aufgabe ist abgeschlossen, wenn die Vorlesung Argentiniens falsches BIP pro Kopf nicht mehr als gültig darstellt und die Abbildung oder Erklärung das Ergebnis verdeutlicht.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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

Vorherrschende Sprache
JavaScript
Sterne
73
Forks
34
Ø Merge
28 Min.
Gemergte PRs (30 T.)
5

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus QuantEcon/lecture-python-programming

Alle Issues in QuantEcon/lecture-python-programming

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.