0

I am trying to convert a 2 digit year to a 4 digit year using this command:

df['year'] = df['year'].strftime('%Y')

this is the error: AttributeError: 'Series' object has no attribute 'strftime'

I get, not sure why its not working I have used this command many times before.

here is my sample data enter image description here

and here is my desired output: enter image description here

Samir112
  • 125
  • 1
  • 12
  • You need to be referring to a specific row not the entire `year` series. – OTheDev Apr 11 '22 at 21:29
  • After a short look at the docs you would see it is "df['year'].dt.strftime('%Y')" – Michael Butscher Apr 11 '22 at 21:30
  • [here](https://pandas.pydata.org/docs/reference/api/pandas.Series.dt.strftime.html) possibly – OTheDev Apr 11 '22 at 21:30
  • What are the rules? Can't you just add `'19'` (or `1900` if integers)? – mozway Apr 11 '22 at 21:31
  • "50" is not a date/time value. It's never going to have a `strftime` member. And two-digit years less than 70 are interpreted as 21st Century, so you'd get 2050, not 1950. You need to manipulate this as an integer first. – Tim Roberts Apr 11 '22 at 21:32

0 Answers0