Extraire

Introduction au data engineering

Vincent Vankrunkelsven

Data Engineer @ DataCamp

Extraire des données : qu’est-ce que cela signifie ?

Diagramme représentant une phase d’extraction simple

Introduction au data engineering

Extraire depuis des fichiers texte

Non structurées

  • Texte brut
  • Ex. chapitre d’un livre

 

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

Fichiers plats

  • Ligne = enregistrement
  • Colonne = attribut
  • Ex. .tsv ou .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 au data engineering

JSON

  • JavaScript Object Notation
  • Semi-structuré
  • Atomique
    • number
    • string
    • boolean
    • null
  • Composé
    • 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 au data engineering

Données sur le Web

Requêtes

Diagramme représentant le modèle requête-réponse

Exemple

  1. Aller sur Google
  2. Requête au serveur Google
  3. Google renvoie la page web
Introduction au data engineering

Données sur le Web via des API

  • Envoi de données au format JSON
  • API : interface de programmation d’applications
  • Exemples
    • API Twitter
{ "statuses": [{ "created_at": "Mon May 06 20:01:29 +0000 2019", "text": "this is a tweet"}] }
  • API Hackernews
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 au data engineering

Données dans les bases

Bases de données applicatives

  • Transactions
  • Insertions ou modifications
  • OLTP
  • Orientées lignes

Bases de données analytiques

  • OLAP
  • Orientées colonnes
Introduction au data engineering

Extraction depuis des bases de données

Chaîne/URI de connexion

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

Utilisation en 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 au data engineering

Passons à la pratique !

Introduction au data engineering

Preparing Video For Download...