0Pricing
Data Science Academy · Lekcja

Strefy czasowe i zakresy dat

Lokalizowanie i generowanie dat

Strefy czasowe i zakresy dat to bezpłatna lekcja Data Science Academy na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Data Science Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Data Science Academy zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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. ⏰

Często zadawane pytania

Czy lekcja „Strefy czasowe i zakresy dat” jest bezpłatna?

Tak — pełny tekst „Strefy czasowe i zakresy dat” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Data Science Academy, przejdź na CoddyKit PRO. Kurs Data Science Academy zawiera 4 lekcji w sumie.

Co nauczysz się w „Strefy czasowe i zakresy dat”?

Lokalizowanie i generowanie dat Ćwiczysz Data Science Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Data Science Academy?

Nie wymagamy żadnego doświadczenia. Data Science Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.

Ile czasu zajmuje lekcja „Strefy czasowe i zakresy dat”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Data Science Academy?

Tak. Każda lekcja Data Science Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Parsowanie ciągów znaków do dat i czasu
  2. Wyodrębnianie roku, miesiąca i dnia tygodnia
  3. Resampling dzienny lub miesięczny
  4. Strefy czasowe i zakresy dat
← Powrót do Data Science Academy