Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting pandas.tslib.Timestamp to datetime python

Tags:

python

pandas

I have a df time series. I extracted the indexes and want to convert them each to datetime. How do you go about doing that? I tried to use pandas.to_datetime(x) but it doesn't convert it when I check after using type()

like image 445
user1234440 Avatar asked Sep 15 '14 15:09

user1234440


People also ask

Is timestamp the same as datetime pandas?

Timestamp is the pandas equivalent of python's Datetime and is interchangeable with it in most cases. It's the type used for the entries that make up a DatetimeIndex, and other timeseries oriented data structures in pandas.

How do I remove timestamp from time in Python?

To remove the time from a datetime object in Python, convert the datetime to a date using date(). You can also use strftime() to create a string from a datetime object without the time. When working in Python, many times we need to create variables which represent dates and times.


1 Answers

Just try to_pydatetime()

>>> import pandas as pd >>> t = pd.tslib.Timestamp('2016-03-03 00:00:00') >>> type(t) pandas.tslib.Timestamp >>> t.to_pydatetime() datetime.datetime(2016, 3, 3, 0, 0) 

Change to datetime.date type

>>> t.date() datetime.date(2016, 3, 3) 
like image 84
GoingMyWay Avatar answered Sep 22 '22 14:09

GoingMyWay