Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (50.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 (107k 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
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...