Extract

Introduction to Data Engineering

Vincent Vankrunkelsven

Data Engineer @ DataCamp

Extracting data: what does it mean?

Diagram representing simple extract phase

Introduction to Data Engineering

Extract from text files

Unstructured

  • Plain text
  • E.g. chapter from a book

 

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

Flat files

  • Row = record
  • Column = attribute
  • E.g. .tsv or .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
Introduction to Data Engineering

JSON

  • JavaScript Object Notation
  • Semi-structured
  • Atomic
    • number
    • string
    • boolean
    • null
  • Composite
    • 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
Introduction to Data Engineering

Data on the Web

Requests

Diagram representing request-response model

Example

  1. Browse to Google
  2. Request to Google Server
  3. Google responds with web page
Introduction to Data Engineering

Data on the Web through APIs

  • Send data in JSON format
  • API: application programming interface
  • Examples
    • Twitter API
{ "statuses": [{ "created_at": "Mon May 06 20:01:29 +0000 2019", "text": "this is a tweet"}] }
  • 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': .... }
Introduction to Data Engineering

Data in databases

Applications databases

  • Transactions
  • Inserts or changes
  • OLTP
  • Row-oriented

Analytical databases

  • OLAP
  • Column-oriented
Introduction to Data Engineering

Extraction from databases

Connection string/URI

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

Use 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)
Introduction to Data Engineering

Let's practice!

Introduction to Data Engineering

Preparing Video For Download...