04 · Datenimport aus Dateien und APIs
einlesen_pipeline.svg
Abbildung · Quellcode
Erzeugt von einlesen_pipeline() in lib/diagrams.py, Zeile 232–263.
Python
Python-Code: in eine Datei mit Endung
.py schreiben und mit dem ▶-Knopf in VS Code ausführen – oder Zeile für Zeile in die Python-Konsole. Setzt die in Modul 02 eingerichtete Umgebung voraus.def einlesen_pipeline() -> str: b = [eyebrow(40, 40, "Von der Rohdatei zum DataFrame")] cy = 110 # Rohdatei b.append(rect(40, cy - 40, 190, 118, r=12, fill=T["soft"])) b.append(txt(56, cy - 18, "labor.csv", size=12.5, fill=T["ink"], w=600, mono=True)) for k, ln in enumerate(["patient_id;laktat", "1042;3,4", "1043;1,6"]): b.append(txt(56, cy + 6 + k * 20, ln, size=11, fill=T["mut"], mono=True)) # Parser px = 300 b.append(rect(px, cy - 40, 200, 118, r=12, fill=T["card"], stroke=T["rule"])) b.append(txt(px + 100, cy - 18, "einlesen", size=12.5, fill=T["acc2"], w=600, anchor="middle")) for k, (lab) in enumerate(["Trennzeichen ;", "Encoding UTF-8", "Dezimal ,", "Header Zeile 1"]): yy = cy + 2 + k * 19 b.append(txt(px + 16, yy, lab.split(" ")[0], size=10.5, fill=T["mut"])) b.append(txt(px + 184, yy, lab.split(" ")[1], size=10.5, fill=T["acc"], w=600, anchor="end", mono=True)) # DataFrame dx = 570 b.append(rect(dx, cy - 40, 150, 118, r=12, fill=T["card"], stroke=T["rule"])) b.append(txt(dx + 75, cy - 18, "DataFrame", size=12.5, fill=T["ink"], w=600, anchor="middle")) b.append(rect(dx + 16, cy - 4, 118, 62, r=6, fill=T["soft"])) for k in range(3): b.append(line(dx + 16, cy + 16 + k * 18, dx + 134, cy + 16 + k * 18, stroke=T["hair"])) b.append(line(dx + 62, cy - 4, dx + 62, cy + 58, stroke=T["hair"])) b.append(arrow(238, cy + 18, 296, color=T["mut"])) b.append(arrow(508, cy + 18, 566, color=T["mut"])) b.append(txt(40, cy + 108, "Stolperfallen:", size=11, fill=T["warn"], w=700)) b.append(txt(140, cy + 108, "„;“ statt „,“ · Latin-1 statt UTF-8 · Dezimalkomma · fehlender Header", size=11, fill=T["mut"])) return canvas(760, 250, "".join(b), "Einlese-Pipeline: Aus einer Rohdatei wird über bewusste Parser-Entscheidungen " "(Trennzeichen, Encoding, Dezimalzeichen, Header) ein sauberer DataFrame.")