If I have a dataframe with a datetime
column, created using pd.to_datetime(column), I can strip the time part of it using df.col_name.dt.date.
But this column now doesn't let me access .dt method. I can't access .dt.weeks etc methods.
Can we not strip the time part of a datetime
in pandas without losing the .dt method?
eg:
df = pd.DataFrame({'td': ['2012-12-03']})
df['td'] = pd.to_datetime(df['td'])
df['td'][0] # shows first element, which has time along with date
df['td'] = df['td'].dt.date
df['td'][0] # shows first element, which has only date
df['td'].dt # throws error