मान लें, आपके पास एक टाइम सीरीज है और एशियाई टाइम ज़ोन को लोकलाइज़ करने का परिणाम:
Index is: DatetimeIndex(['2020-01-05 00:30:00+05:30', '2020-01-12 00:30:00+05:30',
'2020-01-19 00:30:00+05:30', '2020-01-26 00:30:00+05:30',
'2020-02-02 00:30:00+05:30'],
dtype='datetime64[ns, Asia/Calcutta]', freq='W-SUN')
समाधान
एक डेटाफ्रेम परिभाषित करें
pd.date_range() फ़ंक्शन का उपयोग करके टाइम सीरीज बनाएं, start को '2020-01-01 00:30', periods=5, freq='W', tz='Asia/Calcutta' के रूप में सेट करें और इसे time_index के रूप में स्टोर करें।
time_index = pd.date_range('2020-01-01 00:30', periods=5, freq='W', tz='Asia/Calcutta')
लोकलाइज़्ड टाइम ज़ोन को time_index से स्टोर करने के लिए df.index सेट करें
df.index = time_index
अंत में लोकलाइज़्ड टाइमज़ोन प्रिंट करें
उदाहरण
बेहतर समझ के लिए निम्न कोड देखें:
import pandas as pd
df = pd.DataFrame({'Id':[1,2,3,4,5], 'City':['Mumbai','Pune','Delhi','Chennai','Kolkata']})
time_index = pd.date_range('2020-01-01 00:30', periods=5, freq='W', tz='Asia/Calcutta')
df.index = time_index
print("DataFrame is:\n", df)
print("Index is:\n", df.index)
आउटपुट
DataFrame is:
Id City
2020-01-05 00:30:00+05:30 1 Mumbai
2020-01-12 00:30:00+05:30 2 Pune
2020-01-19 00:30:00+05:30 3 Delhi
2020-01-26 00:30:00+05:30 4 Chennai
2020-02-02 00:30:00+05:30 5 Kolkata
Index is: DatetimeIndex(['2020-01-05 00:30:00+05:30', '2020-01-12 00:30:00+05:30',
'2020-01-19 00:30:00+05:30', '2020-01-26 00:30:00+05:30',
'2020-02-02 00:30:00+05:30'],
dtype='datetime64[ns, Asia/Calcutta]', freq='W-SUN')