close

How can I convert my datetime column in pandas all to the same timezone

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How can I convert my datetime column in pandas all to the same timezone in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How can I convert my datetime column in pandas all to the same timezone?

  1. How can I convert my datetime column in pandas all to the same timezone?

    I think that it is not necessary to apply lambdas:
    df_res['DateTime'] = pd.to_datetime(df_res['DateTime'], utc=True)

  2. I convert my datetime column in pandas all to the same timezone

    I think that it is not necessary to apply lambdas:
    df_res['DateTime'] = pd.to_datetime(df_res['DateTime'], utc=True)

Method 1

I think that it is not necessary to apply lambdas:

df_res['DateTime'] = pd.to_datetime(df_res['DateTime'], utc=True)

Method 2

You can check this:

df = pd.DataFrame({
    'time': [
        '2017-11-02 19:49:28-08:00', 
        '2017-11-27 07:32:22-07:00', 
        '2017-12-27 17:01:15-07:00'
    ]
})

df['time'] = pd.to_datetime(df['time'])

df['time'].apply(lambda x: pd.to_datetime(x).tz_localize('US/Eastern'))
0   2017-11-03 03:49:28-04:00
1   2017-11-27 14:32:22-05:00
2   2017-12-28 00:01:15-05:00
Name: time, dtype: datetime64[ns, US/Eastern]

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read