Het belang van flatfiles in data science

Introductie tot data importeren in Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

Flatfiles

titanic.csv

PassengerId,Survived,Pclass,Name,Gender,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked
1,0,3,"Braund, Mr. Owen Harris",male,22,1,0,A/5 21171,7.25,,S
2,1,1,"Cumings, Mrs. John Bradley",female,38,1,0,PC 17599,71.2833,C85,C
3,1,3,"Heikkinen, Miss. Laina",female,26,0,0,STON/O2.3101282,7.925,,S
Introductie tot data importeren in Python

Flatfiles

titanic.csv

PassengerId,Survived,Pclass,Name,Gender,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked

1,0,3,"Braund, Mr. Owen Harris",male,22,1,0,A/5 21171,7.25,,S

2,1,1,"Cumings, Mrs. John Bradley",female,38,1,0,PC 17599,71.2833,C85,C

3,1,3,"Heikkinen, Miss. Laina",female,26,0,0,STON/O2.3101282,7.925,,S

pijl

                        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
Introductie tot data importeren in Python

Flatfiles

titanic.csv

titanic.csv met een rij gemarkeerd pijl

                        Name      Sex  Cabin  Survived
     Braund, Mr. Owen Harris     male    NaN         0
  Cumings, Mrs. John Bradley   female    C85         1
      Heikkinen, Miss. Laina   female    NaN         1
Introductie tot data importeren in Python

Flatfiles

titanic.csv

titanic.csv met een kolom gemarkeerd pijl

                        Name      Sex  Cabin  Survived
     Braund, Mr. Owen Harris     male    NaN         0
  Cumings, Mrs. John Bradley   female    C85         1
      Heikkinen, Miss. Laina   female    NaN         1
Introductie tot data importeren in Python

Flatfiles

  • Tekstbestanden met records
  • Dus tabeldata
  • Record: rij met velden of attributen

 

titanic.csv

PassengerId,Survived,Pclass,Name,Gender,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked
1,0,3,"Braund, Mr. Owen Harris",male,22,1,0,A/5 21171,7.25,,S
2,1,1,"Cumings, Mrs. John Bradley",female,38,1,0,PC 17599,71.2833,C85,C
3,1,3,"Heikkinen, Miss. Laina",female,26,0,0,STON/O2.3101282,7.925,,S
Introductie tot data importeren in Python

Flatfiles

  • Tekstbestanden met records
  • Dus tabeldata
  • Record: rij met velden of attributen
  • Kolom: feature of attribuut

titanic.csv

titanic.csv met een rij gemarkeerd pijl

Introductie tot data importeren in Python

Flatfiles

  • Tekstbestanden met records
  • Dus tabeldata
  • Record: rij met velden of attributen
  • Kolom: feature of attribuut

titanic.csv

titanic.csv met een kolom gemarkeerd pijl

Introductie tot data importeren in Python

Header

titanic.csv

________________________________________________________________________
PassengerId,Survived,Pclass,Name,Gender,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked
________________________________________________________________________
1,0,3,"Braund, Mr. Owen Harris",male,22,1,0,A/5 21171,7.25,,S   
2,1,1,"Cumings, Mrs. John Bradley",female,38,1,0,PC 17599,71.2833,C85,C
3,1,3,"Heikkinen, Miss. Laina",female,26,0,0,STON/O2.3101282,7.925,,S
Introductie tot data importeren in Python

Header

titanic.csv

________________________________________________________________________
PassengerId,Survived,Pclass,Name,Gender,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked
________________________________________________________________________
1,0,3,"Braund, Mr. Owen Harris",male,22,1,0,A/5 21171,7.25,,S   
2,1,1,"Cumings, Mrs. John Bradley",female,38,1,0,PC 17599,71.2833,C85,C
3,1,3,"Heikkinen, Miss. Laina",female,26,0,0,STON/O2.3101282,7.925,,S
Introductie tot data importeren in Python

Bestandsextensie

  • .csv - comma-separated values
  • .txt - tekstbestand
  • komma’s, tabs - delimiters/scheidingstekens
Introductie tot data importeren in Python

Tab-gescheiden bestand

MNIST.txt

pixel149    pixel150    pixel151    pixel152    pixel153
0           0           0           0           0    
86          250         254         254         254    
0           0           0           9           254    
0           0           0           0           0    
103         253         253         253         253    
0           0           0           0           0    
0           0           0           0           0        
0           0           0           0           41        
253         253         253         253         253    
Introductie tot data importeren in Python

Tab-gescheiden bestand

MNIST.txt

pixel149    pixel150    pixel151    pixel152    pixel153
0           0           0           0           0    
86          250         254         254         254    
0           0           0           9           254    
0           0           0           0           0    
103         253         253         253         253    
0           0           0           0           0    
0           0           0           0           0        
0           0           0           0           41        
253         253         253         253         253    

                                         MNIST-afbeelding: mnist.png

Introductie tot data importeren in Python

Hoe importeer je flatfiles?

  • Twee hoofdpackages: NumPy, pandas

ch_1_2.026.png

  • Je leert hier importeren:
    • Flatfiles met numerieke data (MNIST)
    • Flatfiles met numerieke data en tekst (titanic.csv)
Introductie tot data importeren in Python

Laten we oefenen!

Introductie tot data importeren in Python

Preparing Video For Download...