Extragere

Introducere în Data Engineering

Vincent Vankrunkelsven

Data Engineer @ DataCamp

Extragerea datelor: ce înseamnă?

Diagramă reprezentând faza simplă de extragere

Introducere în Data Engineering

Extragere din fișiere text

Nestructurate

  • Text simplu
  • Ex. capitol dintr-o carte

 

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

Fișiere plate

  • Rând = înregistrare
  • Coloană = atribut
  • Ex. .tsv sau .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
Introducere în Data Engineering

JSON

  • JavaScript Object Notation
  • Semi-structurat
  • Atomic
    • number
    • string
    • boolean
    • null
  • Compus
    • 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
Introducere în Data Engineering

Date de pe Web

Cereri

Diagramă reprezentând modelul cerere-răspuns

Exemplu

  1. Accesare Google
  2. Cerere către serverul Google
  3. Google răspunde cu pagina web
Introducere în Data Engineering

Date de pe Web prin API-uri

  • Trimitere date în format JSON
  • API: interfață de programare a aplicațiilor
  • Exemple
    • 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': .... }
Introducere în Data Engineering

Date în baze de date

Baze de date aplicative

  • Tranzacții
  • Inserări sau modificări
  • OLTP
  • Orientate pe rânduri

Baze de date analitice

  • OLAP
  • Orientate pe coloane
Introducere în Data Engineering

Extragere din baze de date

Șir de conexiune/URI

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

Utilizare în 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)
Introducere în Data Engineering

Să exersăm!

Introducere în Data Engineering

Preparing Video For Download...