Willkommen zum Kurs!

Einführung in das Importieren von Daten in Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

Daten importieren

  • Flat Files, z. B. .txts, .csvs
  • Dateien von anderer Software

 

ch_1_1_v2.004.png

Einführung in das Importieren von Daten in Python

Daten importieren

  • Flat Files, z. B. .txts, .csvs
  • Dateien von anderer Software
  • Relationale Datenbanken

ch_1_1_v2.005.png

Einführung in das Importieren von Daten in Python

Einfache Textdateien

ch_1_1_v2.007.png

Einführung in das Importieren von Daten in Python

Tabellendaten

titanic.csv

                        Name      Sex  Cabin  Survived
     Braund, Mr. Owen Harris     male    NaN         0
  Cumings, Mrs. John Bradley   female    C85         1
      Heikkinen, Miss. Laina   female    NaN         1
Futrelle, Mrs. Jacques Heath   female   C123         1
    Allen, Mr. William Henry     male    NaN         0
1 Quelle: Kaggle
Einführung in das Importieren von Daten in Python

Tabellendaten

titanic.csv

titanic.csv mit einer hervorgehobenen Zeile

Einführung in das Importieren von Daten in Python

Tabellendaten

titanic.csv

titanic.csv mit einer markierten Spalte

  • Flat File
Einführung in das Importieren von Daten in Python

Eine Textdatei lesen

filename = 'huck_finn.txt'

file = open(filename, mode='r') # 'r' is to read
text = file.read()
file.close()
Einführung in das Importieren von Daten in Python

Eine Textdatei ausgeben

print(text)
YOU don't know about me without you have read a book by
the name of The Adventures of Tom Sawyer; but that 
ain't no matter. That book was made by Mr. Mark Twain,
and he told the truth, mainly. There was things which 
he stretched, but mainly he told the truth.  That is 
nothing. never seen anybody but lied one time or 
another, without it was Aunt Polly, or the widow, or 
maybe Mary. Aunt Polly--Tom's Aunt Polly, she is--and
Mary, and the Widow Douglas is all told about in that
book, which is mostly a true book, with some 
stretchers, as I said before.
Einführung in das Importieren von Daten in Python

In eine Datei schreiben

filename = 'huck_finn.txt'
file = open(filename, mode='w')  # 'w' is to write
file.close()
Einführung in das Importieren von Daten in Python

Kontextmanager mit

with open('huck_finn.txt', 'r') as file:
    print(file.read())
YOU don't know about me without you have read a book by
the name of The Adventures of Tom Sawyer; but that 
ain't no matter. That book was made by Mr. Mark Twain,
and he told the truth, mainly. There was things which 
he stretched, but mainly he told the truth.  That is 
nothing. never seen anybody but lied one time or 
another, without it was Aunt Polly, or the widow, or 
maybe Mary. Aunt Polly--Tom's Aunt Polly, she is--and 
Mary, and the Widow Douglas is all told about in that 
book, which is mostly a true book, with some 
stretchers, as I said before.
Einführung in das Importieren von Daten in Python

In den Übungen wirst du:

  • Dateien auf die Konsole ausgeben
  • Bestimmte Zeilen ausgeben
  • Über Flat Files reden
Einführung in das Importieren von Daten in Python

Lass uns üben!

Einführung in das Importieren von Daten in Python

Preparing Video For Download...