EDA Workflow
EDA Workflow
Section titled “EDA Workflow”EDA ไม่ใช่แค่ “ดูข้อมูล” แต่เป็นกระบวนการที่มีขั้นตอนชัดเจน ทำตามลำดับนี้ทุกครั้งจะช่วยให้ไม่พลาดอะไรสำคัญ
Step 1: Load — โหลดข้อมูล
Section titled “Step 1: Load — โหลดข้อมูล”import pandas as pd
# อ่านพร้อมกำหนด dtype ที่รู้ล่วงหน้าdf = pd.read_csv("sales_2024.csv", dtype={"zipcode": str, "product_id": str})Step 2: Inspect — ตรวจสอบภาพรวม
Section titled “Step 2: Inspect — ตรวจสอบภาพรวม”# 5 คำสั่งที่ต้องรันทุกครั้งprint(df.shape) # จำนวนแถว x คอลัมน์print(df.dtypes) # ชนิดข้อมูลdf.info() # สรุปรวม + non-null countprint(df.describe()) # สถิติเบื้องต้น (ตัวเลข)print(df.head()) # ดูข้อมูลตัวอย่าง
# เสริม: ดูค่าว่างprint(df.isna().sum().sort_values(ascending=False))
# เสริม: ดูค่าซ้ำprint(df.duplicated().sum())Step 3: Clean — ทำความสะอาด
Section titled “Step 3: Clean — ทำความสะอาด”# 3a. จัดการ missing valuesdf = df.dropna(subset=["customer_id"]) # ลบแถวที่ไม่มี customerdf["price"] = df["price"].fillna(0)
# 3b. แปลง dtypedf["price"] = pd.to_numeric(df["price"], errors="coerce")df["order_date"] = pd.to_datetime(df["order_date"])
# 3c. clean stringsdf["category"] = df["category"].str.strip().str.lower()
# 3d. ลบ duplicatesdf = df.drop_duplicates(subset=["order_id"])Step 4: Explore — สำรวจ pattern
Section titled “Step 4: Explore — สำรวจ pattern”# ถามคำถาม → หาคำตอบด้วยข้อมูล# Q1: หมวดไหนขายดีสุด?df.groupby("category")["revenue"].sum().sort_values(ascending=False)
# Q2: ยอดขายเป็นอย่างไรตามเวลา?df.groupby(df["order_date"].dt.month)["revenue"].sum()
# Q3: ลูกค้ากลุ่มไหนจ่ายมากสุด?df.groupby("region")["revenue"].agg(["sum", "mean", "count"])Step 5: Conclude — สรุปผล
Section titled “Step 5: Conclude — สรุปผล”# สร้าง summary DataFramesummary = df.groupby("category").agg( total_revenue=("revenue", "sum"), avg_order=("revenue", "mean"), order_count=("order_id", "count")).reset_index().sort_values("total_revenue", ascending=False)
# Exportsummary.to_csv("summary_report.csv", index=False)print("EDA Complete!")- Load: File > Import CSV
- Inspect: ดูจำนวนแถว, ใช้ Filter ดูค่าว่าง
- Clean: Find & Replace, Data > Data cleanup
- Explore: Pivot Table, Charts
- Conclude: สร้าง Summary sheet
-- InspectSELECT COUNT(*) FROM sales;SELECT * FROM sales LIMIT 5;-- CleanDELETE FROM sales WHERE customer_id IS NULL;-- ExploreSELECT category, SUM(revenue) FROM sales GROUP BY category;// EDA ใน C ไม่ practical// ใช้ Python/pandas แทนสำหรับงาน EDA