Ladenkov Vladislav
Ladenkov Vladislav

Reputation: 1297

Converting pandas.tslib.Timestamp with tzinfo to datetime python

I ask question right after trying: this.

Have dates:

type(md):
pandas._libs.tslib.Timestamp 

But it look different from the

Timestamp('2016-03-03 00:00:00'),

namely:

Timestamp('2018-02-02 23:59:59+0000', tz='UTC')

So, how can i just ignore tzinfo and convert it to a datetime.datetime

Upvotes: 0

Views: 934

Answers (1)

jeschwar
jeschwar

Reputation: 1314

You can change the time-zone info, i.e., set it to default which is None, and then convert it to Python's datetime object as follows:

ts = pd.Timestamp('2018-02-02 23:59:59+0000', tz='UTC')

ts.tz_convert(None)
# returns Timestamp('2018-02-02 23:59:59')

ts.tz_convert(None).to_pydatetime()
# returns datetime.datetime(2018, 2, 2, 23, 59, 59)

Upvotes: 1

Related Questions