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()
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With