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

สุ่มตัวอย่างใหม่เป็นรายวันหรือรายเดือน

รวมเวลาเป็นช่วงที่ใหญ่ขึ้น

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

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

Too Much Detail to See

Per-second or per-minute data is noisy. Often you really want totals per day or per month. Resampling rolls fine timestamps into bigger buckets. 📊

A Datetime Index First

Resample works on time. So step one is making the datetime column your index with set_index.

df = df.set_index("date")

Meet resample

The resample method groups rows by a time rule, much like groupby but for dates. You then pick how to combine each bucket.

df.resample("D")  # group by day

Daily Totals

Use the rule "D" for days, then sum. This collapses many timestamps into one clean value per day.

daily = df.resample("D")["sales"].sum()

Monthly Summaries

Switch the rule to "ME" for month-end and you get one row per month. Same pattern, bigger bucket.

monthly = df.resample("ME")["sales"].sum()

Rules Are Flexible

The frequency string drives everything: "W" for weeks, "h" for hours, "YE" for year-end. One letter changes your whole view.

df.resample("W")["sales"].sum()  # weekly

Choose Your Aggregation

Sum is not the only option. Swap in mean, max, or count to answer different questions from the same buckets.

df.resample("D")["temp"].mean()

Several Stats at Once

Pass a list to agg to get multiple summaries per bucket in a single tidy table.

df.resample("ME").agg(["sum", "mean"])

Downsample vs Upsample

Going to a coarser bucket is downsampling. Going finer, like daily into hourly, is upsampling and creates empty slots to fill.

df.resample("h").asfreq()  # upsample

Fill the New Gaps

When you upsample, fresh rows arrive empty. Use ffill to carry the last known value forward into them.

df.resample("h").ffill()

Smooth, Then Plot

Resampled series plot beautifully because the noise is gone. A monthly line tells a trend story a raw feed never could.

monthly.plot()

Quick Check

You have minute-level readings but want one average per day.

Recap: Reshape Time

With a datetime index you used resample to roll data into days, weeks, or months, picked an aggregation, and handled upsampled gaps with ffill. ⏳

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

บทเรียน “สุ่มตัวอย่างใหม่เป็นรายวันหรือรายเดือน” ฟรีหรือไม่

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

คุณจะเรียนรู้อะไรในบทเรียน “สุ่มตัวอย่างใหม่เป็นรายวันหรือรายเดือน”

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

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

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

บทเรียน “สุ่มตัวอย่างใหม่เป็นรายวันหรือรายเดือน” ใช้เวลานานแค่ไหน

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

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

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

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

  1. แยกวิเคราะห์สตริงเป็นวันเวลา
  2. แยกปี เดือน และวันในสัปดาห์
  3. สุ่มตัวอย่างใหม่เป็นรายวันหรือรายเดือน
  4. เขตเวลาและช่วงวันที่
← กลับไปที่ Data Science Academy