Generation

generate functionMon, 06 Feb 2023

There is a df Pandas dataframe: date av_temp deviations country 1 1743-12-01 NaN NaN Åland 2 1744-01-01 NaN NaN Åland 3 1744-02-01 NaN NaN Åland 4 1744-03-01 NaN NaN Åland 9 1744-08-01 NaN NaN Åland Create a new column year from date in which you pull out the first 4 digits of the year. Example: 1744-01-01 Date column: 1744 Example: 1744-01-01 Date column: 1744

def yearExtractor(date): year = int(date[:4]) return year df['year'] = df['Date'].apply(yearExtractor)

Questions about programming?Chat with your personal AI assistant