抽出

データエンジニアリング入門

Vincent Vankrunkelsven

Data Engineer, DataCamp

データの抽出とは

シンプルな抽出フェーズを表す図

データエンジニアリング入門

テキストファイルからの抽出

非構造化データ

  • プレーンテキスト
  • 例: 本の1章

 

Call me Ishmael. Some years ago, never 
mind how long precisely, having little or
no money in my purse, and nothing particular
to interest me on shore, I thought ....

フラットファイル

  • 行 = レコード
  • 列 = 属性
  • 例: .tsv.csv

 

Year,Make,Model,Price
1997,Ford,E350,3000.00
1999,Chevy,"Venture Extended Edition",4900.00
1999,Chevy,"Venture Extended Edition",5000.00
1996,Jeep,Grand Cherokee,4799.00
データエンジニアリング入門

JSON

  • JavaScript Object Notation
  • 半構造化データ
  • アトミック型
    • number
    • string
    • boolean
    • null
  • 複合型
    • array
    • object
{
  "an_object": {
    "nested": [
      "one",
      "two",
      "three",
      {
        "key": "four"
      }
    ]
  }
}
import json

result = json.loads('{"key_1": "value_1", "key_2":"value_2"}') print(result["key_1"])
value_1
データエンジニアリング入門

ウェブ上のデータ

リクエスト

リクエストとレスポンスのモデルを表す図

  1. Google にアクセスする
  2. Google サーバーへリクエストを送る
  3. Google がウェブページで応答する
データエンジニアリング入門

API を通じたウェブ上のデータ

  • JSON 形式でデータを送信
  • API: アプリケーションプログラミングインターフェース
    • GitHub API
{ "login": "datacamp", "type": "Organization", "created_at": "2013-05-14T13:01:20Z" }
  • Hackernews API
import requests

response = requests.get("https://hacker-news.firebaseio.com/v0/item/16222426.json") print(response.json())
{'by': 'neis', 'descendants': 0, 'id': 16222426, 'score': 17, 'time': 1516800333, 'title': .... }
データエンジニアリング入門

データベース内のデータ

アプリケーションデータベース

  • トランザクション
  • 挿入や変更
  • OLTP
  • 行指向

分析用データベース

  • OLAP
  • 列指向
データエンジニアリング入門

データベースからの抽出

接続文字列/URI

postgresql://[user[:password]@][host][:port]

Python での利用

import sqlalchemy
connection_uri = "postgresql://repl:password@localhost:5432/pagila" 
db_engine = sqlalchemy.create_engine(connection_uri)

import pandas as pd pd.read_sql("SELECT * FROM customer", db_engine)
データエンジニアリング入門

練習しましょう!

データエンジニアリング入門

Preparing Video For Download...