Extract

Introductie tot Data Engineering

Vincent Vankrunkelsven

Data Engineer, DataCamp

Data extraheren: wat betekent dat?

Diagram van de eenvoudige extract-fase

Introductie tot Data Engineering

Extract uit tekstbestanden

Ongestructureerd

  • Platte tekst
  • Bijv. hoofdstuk uit een boek

 

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 ....

Platte bestanden

  • Rij = record
  • Kolom = attribuut
  • Bijv. .tsv of .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
Introductie tot Data Engineering

JSON

  • JavaScript Object Notation
  • Semi-gestructureerd
  • Atomair
    • number
    • string
    • boolean
    • null
  • Samengesteld
    • 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
Introductie tot Data Engineering

Data op het web

Requests

Diagram van request-response-model

Voorbeeld

  1. Ga naar Google
  2. Request naar Google-server
  3. Google reageert met webpagina
Introductie tot Data Engineering

Data op het web via API's

  • Verstuur data in JSON-indeling
  • API: application programming interface
  • Voorbeelden
    • 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': .... }
Introductie tot Data Engineering

Data in databases

Applicatiedatabases

  • Transacties
  • Invoegen of wijzigen
  • OLTP
  • Rij-georiënteerd

Analytische databases

  • OLAP
  • Kolom-georiënteerd
Introductie tot Data Engineering

Extractie uit databases

Verbindingsstring/URI

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

Gebruik in 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)
Introductie tot Data Engineering

Laten we oefenen!

Introductie tot Data Engineering

Preparing Video For Download...