'How to convert double values from df to year values/strings? [duplicate]
I have a dataframe with year values like: 2014.0, 2013.0... as float values. I would need to convert these values to year format, like 2014, 2013... I tried converting them to string, but I get "2014.0", "2013.0"... How could I convert them to year, not double or strings? This is what I tried for string conversion:
df['year']=df['year'].astype(str)
And then:
df['year']= pd.to_datetime(df['year'], format='%Y')
But this gave me results like: 1640995200000 and so on. How could I convert the doubles to reasonable year format?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
