日次または月次にresampleする
時間をより大きな区切りにまとめる
「日次または月次にresampleする」はCoddyKit上の無料Data Science Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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 dayDaily 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() # weeklyChoose 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() # upsampleFill 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. ⏳
よくある質問
「日次または月次にresampleする」レッスンは無料ですか?
はい。「日次または月次にresampleする」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Data Science Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Data Science Academyコースには全4レッスンが含まれています。
「日次または月次にresampleする」で何を学びますか?
時間をより大きな区切りにまとめる ブラウザで直接実行するハンズオンコードでData Science Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Data Science Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのData Science Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。
「日次または月次にresampleする」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このData Science Academyレッスンでコードを書いて実行できますか?
はい。すべてのData Science Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 文字列をDatetimeに解析する
- 年、月、曜日を取り出す
- 日次または月次にresampleする
- タイムゾーンと日付範囲