There are dates in this format:
Data 31-01-1982 28-02-1982 31-03-1982 30-04-1982 31-05-1982
Data type: datetime64[ns]
I need to return the value of only the year: that is, get in this DF at the output:
Data 1982 1982 1982 1982 1982
use "accessor" df[col].dt.year
:
In [93]: df Out[93]: Data 0 1982-01-31 1 1982-02-28 2 1982-03-31 3 1982-04-30 4 1982-05-31 In [94]: df['Data'].dt.year Out[94]: 0 1982 1 1982 2 1982 3 1982 4 1982 Name: Data, dtype: int64
to replace the values in the column - dates for the year:
df.loc[:, 'Data'] = df.loc[:, 'Data'].dt.year
A value is trying to be set on a copy of a slice from a DataFrame
. - Max52 pmSource: https://ru.stackoverflow.com/questions/959525/
All Articles