Hi I am new to learning data science and was just trying to play with a data set:
When I check the dtype of a column it shows as object. I want to convert it to a string so I can strip the components into different columns, but changing to string is kind of not working and my strip method/function does not work.
I have a Date column with Date and Time in it like: 2025-05-19 12:08:22
My idea is to convert it to string with:
data_frame_H['Date'] = data_frame_H['Date'].astype('str')
and apply this to it:
df['clean_date'] = df['Date'].str.extract(r'0-9*-0-9*-0-9*', '', regex=True).str.strip()
But when I run this I get:
AttributeError: Can only use .str accessor with string values!
data_frame_H['Date'].dt.date. You'll find all the date accessors in the docs. Same for time,.dt.timeand the other components, eg.dt.year,.dt.microsecond.