1

I am trying to get the year from the index of my Dataframe.

At first I imported like this :

energie = pd.read_csv(io.BytesIO(uploaded['eco2mix-regional-cons-def.csv']), sep=';', index_col='Date', parse_dates=True)

so I have my date in index

and I try to create a new column with the year only.

#Ajout d'une colonne Année

energie_2["Année"] = energie_2.index
energie_2["Année"] = energie_2.Année.apply(lambda Année : Année.split("-")[0])

batt_na = energie_2[energie_2['Stockage batterie'].notna()]
batt_na["Année"].unique()

In the end I get this error:

AttributeError: 'Timestamp' object has no attribute 'split'

I'm a beginner in the python language, what solution can you propose me ?

thank you in advance for your answers.

0 Answers0