Suppose we are interested in converting DatetimeIndex from one time zone to another. Pandas has everything packed up for you.
So this recipe is a short example on How to convert time zone from one time series to another in pandas. Let's get started.
import pandas as pd
Let's pause and look at these imports. Pandas is generally used for performing mathematical operation and preferably over arrays.
df = pd.date_range(start='2020-01-01 09:00', freq='H', periods=3, tz='Asia/Kolkata') print(df)
Here we have created a simple dataframe with some random values and time zone to Asia/Kolkata.
Now our dataset is ready.
Using tz_covert, we have coverted time zone to US/Central.
Once we run the above code snippet, we will see:
Scroll down the ipython to visualize the results.
Difference in time zones is quite visible.