I have a DatetimeIndex
object comprised of two dates given as follows:
import pandas as pd
timestamps = pd.DatetimeIndex(['2014-1-1', '2014-1-2'], freq='D')
which looks like this:
DatetimeIndex(['2014-01-01', '2014-01-02'], dtype='datetime64[ns]', freq='D')
How do I get a list of dates from the timestamps
object? i.e. I want the following:
['2014-01-01', '2014-01-02']
to_native_types() converts the values of timestamps to str format and then tolist() creates a list of str (dates).
timestamps.to_native_types().tolist()
Output
['2014-01-01', '2014-01-02']
Can you try the following:
timestamps.strftime('%Y-%m-%d').tolist()
Output:
['2014-01-01', '2014-01-02']
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