I have 10 columns (dtype: datetime64). I want to remove the date and month from the columns and keep only the year.
10-01-1880 --> Would like to remove day and month
expecting --> 1880
I have 10 columns (dtype: datetime64). I want to remove the date and month from the columns and keep only the year.
10-01-1880 --> Would like to remove day and month
expecting --> 1880
This should do the trick. I am using datetime module https://docs.python.org/3/library/datetime.html
from datetime import datetime
#Convert string to datetime object
datetime_object = datetime.strptime('10-01-1880', '%d-%m-%Y')
#Extract year
print(datetime_object.day)
print(datetime_object.month)
print(datetime_object.year)
#10
#1
#1880