データサイエンスにおけるフラットファイルの重要性

Python でのデータインポート入門

Hugo Bowne-Anderson

Data Scientist at DataCamp

フラットファイル

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
Python でのデータインポート入門

フラットファイル

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

arrow

                        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
Python でのデータインポート入門

フラットファイル

titanic.csv

titanic.csv with a row highlighted arrow

                        Name      Sex  Cabin  Survived
     Braund, Mr. Owen Harris     male    NaN         0
  Cumings, Mrs. John Bradley   female    C85         1
      Heikkinen, Miss. Laina   female    NaN         1
Python でのデータインポート入門

フラットファイル

titanic.csv

titanic.csv with a column highlighted arrow

                        Name      Sex  Cabin  Survived
     Braund, Mr. Owen Harris     male    NaN         0
  Cumings, Mrs. John Bradley   female    C85         1
      Heikkinen, Miss. Laina   female    NaN         1
Python でのデータインポート入門

フラットファイル

  • レコードを含むテキストファイル
  • つまり、テーブル データ
  • レコード: フィールドまたは属性の行

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
Python でのデータインポート入門

フラットファイル

  • レコードを含むテキストファイル
  • つまり、テーブルデータ
  • レコード: フィールドまたは属性の行
  • 列: 機能または属性

titanic.csv

titanic.csv with a row highlighted arrow

Python でのデータインポート入門

フラットファイル

  • レコードを含むテキストファイル
  • つまり、テーブルデータ
  • レコード: フィールドまたは属性の行
  • 列: 機能または属性

titanic.csv

titanic.csv with a column highlighted arrow

Python でのデータインポート入門

ヘッダー

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
Python でのデータインポート入門

ヘッダー

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
Python でのデータインポート入門

ファイル拡張子

  • .CSV - Comma separated values
  • .txt - Text file
  • カンマ、タブ - デリミタ(区切り文字)
Python でのデータインポート入門

タブ区切りファイル

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    
Python でのデータインポート入門

タブ区切りファイル

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:

mnist.png

Python でのデータインポート入門

フラットファイルをインポートするには?

  • 2つの主要パッケージ: NumPy、pandas

ch_1_2.026.png

  • 次のファイルのインポート方法を学ぶ:
    • 数値データを含むフラットファイル(MNIST)
    • 数値データと文字列を含むフラットファイル(titanic.csv)
Python でのデータインポート入門

練習しましょう!

Python でのデータインポート入門

Preparing Video For Download...