0Pricing
Data Science Academy · レッスン

タイムゾーンと日付範囲

日時をローカライズして生成する

「タイムゾーンと日付範囲」はCoddyKit上の無料Data Science Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはData Science Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Data Science Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Time Has a Place

9 a.m. in Tokyo is not 9 a.m. in London. Real-world timestamps need a time zone so they mean the same moment everywhere. 🌍

Naive vs Aware

A timestamp with no zone is called naive. One that knows its zone is aware. Mixing the two leads to silent, painful bugs.

ts = pd.Timestamp("2024-03-15 09:00")
print(ts.tz)  # None means naive

Attach a Zone

Use tz_localize to stamp a naive time with its true zone. This says where the clock reading was actually taken.

ts = ts.tz_localize("Asia/Tokyo")

Convert Between Zones

Once aware, switch zones with tz_convert. The underlying instant stays fixed; only the displayed clock changes.

ts.tz_convert("Europe/London")

Localize, Then Convert

The golden order is localize first, convert second. tz_localize sets the origin zone; tz_convert moves it. Never convert a naive value.

s.dt.tz_localize("UTC").dt.tz_convert("US/Eastern")

UTC Is Your Anchor

Store data in UTC and convert only for display. This avoids confusion and sidesteps daylight-saving headaches entirely.

pd.to_datetime(df["ts"], utc=True)

Generate a Date Range

Need a clean sequence of dates? date_range builds one from a start, an end, and a frequency in a single call.

pd.date_range("2024-01-01", "2024-01-07")

Set the Frequency

The freq argument controls spacing: "D" for daily, "h" for hourly, "ME" for month-end. The same rules you used to resample.

pd.date_range("2024-01-01", periods=12, freq="ME")

Count Instead of End

Skip the end date and pass periods to get exactly that many steps. Handy when you know the count but not the finish.

pd.date_range("2024-01-01", periods=30, freq="D")

Ranges as an Index

A date range makes a perfect index for a complete time series, exposing missing days you can then fill or flag.

df = df.reindex(pd.date_range("2024-01-01", periods=31))

Build Date Features Fast

Pair date_range with the dt accessor to manufacture calendars, fill gaps, or label every day in a forecast horizon.

pd.date_range("2024-01-01", periods=7).day_name()

Quick Check

You have a naive timestamp and want to show it in another zone.

Recap: Zones and Ranges

You localized and converted time zones the right way, leaned on UTC as an anchor, and built clean calendars with date_range. ⏰

よくある質問

「タイムゾーンと日付範囲」レッスンは無料ですか?

はい。「タイムゾーンと日付範囲」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Data Science Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Data Science Academyコースには全4レッスンが含まれています。

「タイムゾーンと日付範囲」で何を学びますか?

日時をローカライズして生成する ブラウザで直接実行するハンズオンコードでData Science Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Data Science Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのData Science Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「タイムゾーンと日付範囲」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このData Science Academyレッスンでコードを書いて実行できますか?

はい。すべてのData Science Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 文字列をDatetimeに解析する
  2. 年、月、曜日を取り出す
  3. 日次または月次にresampleする
  4. タイムゾーンと日付範囲
← Data Science Academyに戻る