Skip to content Skip to sidebar Skip to footer

Pd.to_datetime Returns An Object, Not A Time Series

I am trying to convert my column in a df into a time series. The dataset goes from March 23rd 2015-August 17th 2019 and the dataset looks like this: time

Solution 1:

As commented, the problem might be due to the different timezones. Try passing utc=True to pd.to_datetime:

df['time'] = pd.to_datetime(df['time'],utc=True)
df['time']

Test Data

time1day_active_users02015-03-23 00:00:00-04:0019687.012015-03-24 00:00:00-05:0019437.0

Output:

02015-03-23 04:00:00+00:0012015-03-24 05:00:00+00:00Name:time,dtype:datetime64[ns,UTC]

And then:

df.set_index('time', inplace=True)
df.loc['2015']

gives

1day_active_userstime2015-03-23 04:00:00+00:0019687.02015-03-24 05:00:00+00:0019437.0

Post a Comment for "Pd.to_datetime Returns An Object, Not A Time Series"