I'm working on a column that I converted from a object to a datetime datatype in Pandas. I'm trying to get a count of how many of observations are there for each year.

This is the column: df_raw['filed_date'] and the output is:

198894   2017-12-05
198895   2017-12-05
198896   2017-12-05
198897   2017-12-06
198898   2017-12-06
198899   2017-12-07
Name: filed_date, Length: 198900, dtype: datetime64[ns]

I couldn't find a method to just access the date and then daisy chain it to the value_counts() method. Any advice?


2 Answers 2

from collecitons import Counter
Counter([date.year for date in df_raw['filed_date'].values])

If you Have alreday converted it to datetime object, and want to extract other time related info, it can be done in this way,


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.