โหลดข้อมูลเข้าสู่ฐานข้อมูล SQL ด้วย pandas

ETL and ELT ใน Python

Jake Roach

Data Engineer

โหลดข้อมูลเข้าสู่ฐานข้อมูล SQL ด้วย pandas

ไปป์ไลน์ ETL ที่เน้นส่วนประกอบการโหลดข้อมูล

ETL and ELT ใน Python

โหลดข้อมูลเข้าสู่ฐานข้อมูล SQL ด้วย pandas

ผู้ใช้ข้อมูลที่เข้าถึงฐานข้อมูล SQL

pandas มีเมธอด .to_sql() สำหรับบันทึกข้อมูลลง SQL

  • name
  • con
  • if_exists
  • index
  • index_label
ETL and ELT ใน Python

บันทึกข้อมูลลง Postgres ด้วย pandas

# Create a connection object
connection_uri = "postgresql+psycopg2://repl:password@localhost:5432/market"
db_engine = sqlalchemy.create_engine(connection_uri)
# Use the .to_sql() method to persist data to SQL
clean_stock_data.to_sql(
    name="filtered_stock_data",
    con=db_engine, 
    if_exists="append",
    index=True,
    index_label="timestamps"
)
ETL and ELT ใน Python

ตรวจสอบการบันทึกข้อมูลด้วย pandas

สิ่งสำคัญคือต้องตรวจสอบว่าข้อมูลถูกบันทึกตามที่คาดไว้

  • ตรวจสอบว่าสามารถคิวรีข้อมูลได้
  • ตรวจสอบว่าจำนวนข้อมูลตรงกัน
  • ตรวจสอบว่าทุกแถวมีอยู่ครบถ้วน
# Pull data written to SQL table
to_validate = pd.read_sql("SELECT * FROM cleaned_stock_data", db_engine)
# Validate counts, record equality, etc
...
ETL and ELT ใน Python

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

ETL and ELT ใน Python

Preparing Video For Download...