← Back to Pandas Course | Chapter 10: Time Series | Lesson 7 of 7

Time Zones को संभालना

Timestamps को किसी time zone से जोड़ा जा सकता है ताकि आप regions के बीच सही तरीके से convert कर सकें।

In this page:

  1. Time zones
Syntax
python
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

python
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. #}
आम गलतियां
  1. पहले से aware data पर tz_localize का उपयोग करना
  2. naive को aware datetimes से compare करना
  3. 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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.