Time Zones को संभालना
Timestamps को किसी time zone से जोड़ा जा सकता है ताकि आप regions के बीच सही तरीके से convert कर सकें।
In this page:
Syntax
s = s.tz_localize("Zone/Name")
s = s.tz_convert("Other/Zone")
Time zones
Naive timestamps में कोई zone नहीं होता। tz_localize naive times को एक zone से जोड़ता है, और tz_convert किसी aware time को दूसरी zone में बदलता है। aware और naive timestamps को compare करने पर error आता है, इसलिए consistent रहें। data को UTC में store करें और display के लिए convert करें।
Note:
आंतरिक रूप से UTC का उपयोग करें और सिर्फ presentation के लिए convert करें।
उदाहरण: Time zones
import pandas as pd
ts = pd.Timestamp("2024-06-01 12:00")
utc = ts.tz_localize("UTC")
print(utc)
print(utc.tz_convert("Asia/Tokyo"))
# Output:
# 2024-06-01 12:00:00+00:00
# 2024-06-01 21:00:00+09:00
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- पहले से aware data पर tz_localize का उपयोग करना
- naive को aware datetimes से compare करना
- daylight saving shifts को नज़रअंदाज़ करना
चैप्टर सारांश
- tz_localize एक zone जोड़ता है
- tz_convert zones बदलता है
- UTC में store करें
- naive और aware को न मिलाएं
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: