Mar-25-2019, 04:24 PM
Hi,
I have a date column in a data frame that looks like this:
(Year-Month-Day)
2017-09-21
2018-11-25
I am trying to create a function that considers only the year, I have been trying the following.
df[df['DateColumn'].str[:4]=='2017']
But I am receiving this error:
AttributeError: Can only use .str accessor with string values, which use np.object_ dtype in pandas
Any chance to point what I am missing here? Should I change the column to strings, or is there a way to do something similar with the series?
Thank you for your help,
Wendy
I have a date column in a data frame that looks like this:
(Year-Month-Day)
2017-09-21
2018-11-25
I am trying to create a function that considers only the year, I have been trying the following.
df[df['DateColumn'].str[:4]=='2017']
But I am receiving this error:
AttributeError: Can only use .str accessor with string values, which use np.object_ dtype in pandas
Any chance to point what I am missing here? Should I change the column to strings, or is there a way to do something similar with the series?
Thank you for your help,
Wendy