Extract

Data Engineering เบื้องต้น

Vincent Vankrunkelsven

Data Engineer, DataCamp

การแยกข้อมูล (extract) คืออะไร

แผนภาพแสดงขั้นตอน extract แบบง่าย

Data Engineering เบื้องต้น

การแยกข้อมูลจากไฟล์ข้อความ

ไม่มีโครงสร้าง (Unstructured)

  • ข้อความล้วน
  • เช่น เนื้อหาบทหนึ่งในหนังสือ

 

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 file

  • แถว = ระเบียนข้อมูล
  • คอลัมน์ = แอตทริบิวต์
  • เช่น .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
Data Engineering เบื้องต้น

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
Data Engineering เบื้องต้น

ข้อมูลบนเว็บ

คำขอ (Requests)

แผนภาพแสดงโมเดล request-response

ตัวอย่าง

  1. เข้าเว็บไซต์ Google
  2. ส่งคำขอไปยังเซิร์ฟเวอร์ของ Google
  3. Google ตอบกลับด้วยหน้าเว็บ
Data Engineering เบื้องต้น

ข้อมูลบนเว็บผ่าน API

  • ส่งข้อมูลในรูปแบบ JSON
  • API: application programming interface
  • ตัวอย่าง
    • 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': .... }
Data Engineering เบื้องต้น

ข้อมูลในฐานข้อมูล

ฐานข้อมูลของแอปพลิเคชัน

  • ธุรกรรม
  • การเพิ่มหรือเปลี่ยนแปลงข้อมูล
  • OLTP
  • จัดเก็บแบบแถว (row-oriented)

ฐานข้อมูลเชิงวิเคราะห์

  • OLAP
  • จัดเก็บแบบคอลัมน์ (column-oriented)
Data Engineering เบื้องต้น

การแยกข้อมูลจากฐานข้อมูล

Connection string/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)
Data Engineering เบื้องต้น

มาฝึกกันเถอะ!

Data Engineering เบื้องต้น

Preparing Video For Download...