0Pricing
Data Science Academy · บทเรียน

แยกวิเคราะห์วันที่และกำหนด dtypes ขณะโหลด

กำหนดชนิดข้อมูลให้ถูกต้องตั้งแต่เวลานำเข้า

แยกวิเคราะห์วันที่และกำหนด dtypes ขณะโหลด เป็นบทเรียน Data Science Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Data Science Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Types Matter From the Start

When pandas reads a file it guesses each column's dtype. Get types right at load time and every later step gets simpler. 🧱

Dates Arrive as Text

A date like 2024-03-01 looks like a date to you, but pandas reads it as a plain string unless you ask otherwise.

Parse Dates on Load

The parse_dates option converts listed columns into real datetime values during the read, no extra step needed.

df = pd.read_csv("sales.csv",
  parse_dates=["order_date"])

Why It Pays Off

Once a column is a real datetime, you can sort by time, filter date ranges, and pull out the month with ease.

Help With Odd Formats

For unusual layouts, pass a format string so pandas parses fast and never guesses wrong on day-month order.

df = pd.read_csv("eu.csv",
  parse_dates=["d"], date_format="%d/%m/%Y")

Force Specific dtypes

The dtype option lets you declare a column's type yourself, overriding pandas guesses with a clean dictionary.

df = pd.read_csv("data.csv",
  dtype={"zip": "string"})

Keep Leading Zeros

Codes like 00123 lose their zeros if read as numbers. Forcing the column to string preserves them exactly as written.

df = pd.read_csv("ids.csv",
  dtype={"product_code": str})

Shrink Memory With Types

Reading whole numbers as int32 instead of the default int64 can halve memory on big files. Choose the smallest type that fits.

df = pd.read_csv("big.csv",
  dtype={"count": "int32"})

Repeated Text? Use category

Columns with few repeated values, like a status field, shrink dramatically when stored as the category dtype.

df = pd.read_csv("orders.csv",
  dtype={"status": "category"})

Verify After Loading

Always confirm the result. Checking dtypes shows exactly how pandas typed each column so surprises never reach your analysis.

print(df.dtypes)

Fix Types Later If Needed

Missed one? You can still convert afterward with astype, but doing it at load is cleaner and a little faster.

df["count"] = df["count"].astype("int32")

Quick Check

A column of dates is loading as plain text. What fixes it during read?

Recap: Right Types, Less Pain

You can now parse dates, force string and numeric types, and use category for repeats, all at load time. Verify with dtypes and move on. 🎉

คำถามที่พบบ่อย

บทเรียน “แยกวิเคราะห์วันที่และกำหนด dtypes ขณะโหลด” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “แยกวิเคราะห์วันที่และกำหนด dtypes ขณะโหลด” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Data Science Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “แยกวิเคราะห์วันที่และกำหนด dtypes ขณะโหลด”

กำหนดชนิดข้อมูลให้ถูกต้องตั้งแต่เวลานำเข้า คุณปฏิบัติ Data Science Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Data Science Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Data Science Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “แยกวิเคราะห์วันที่และกำหนด dtypes ขณะโหลด” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Data Science Academy นี้ได้ไหม

ได้ บทเรียน Data Science Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. read_csv และตัวเลือกที่มีประโยชน์
  2. เปิดชีต Excel ใน pandas
  3. แยกวิเคราะห์วันที่และกำหนด dtypes ขณะโหลด
  4. บันทึกผลลัพธ์เป็น CSV และ Excel
← กลับไปที่ Data Science Academy