0 votes
1 view
in Data Science by (43.2k points)

I have the following:

> date1

Timestamp('2014-01-23 00:00:00', tz=None)

> date2

datetime.date(2014, 3, 26)

and I could use pandas.to_datetime() to convert from Timestamps to datetime objects, but it doesn't seem to work:

> pd.to_datetime(date1)   

Timestamp('2014-01-23 00:00:00', tz=None)

Why? How can I convert between these two formats?

1 Answer

0 votes
by (92.8k points)

You can simply use the to_pydatetime function to be more explicit, refer the following code:

In [11]: ts = pd.Timestamp('2014-01-23 00:00:00', tz=None)

In [12]: ts.to_pydatetime()

Out[12]: datetime.datetime(2014, 1, 23, 0, 0)

If you want to learn more about Pandas then visit this Python Course designed by the industrial experts.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...