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 convert all date values to years. Example: 1744-01-01 Date column: 1744

def get_year(date): return int(date[:4]) def get_month(date): return int(date[5:7]) def get_day(date): return int(date[8:]) df['year'] = df['date'].apply(get_year) df['month'] = df['date'].apply(get_month) df['day'] = df['date'].apply(get_day)

Questions about programming?Chat with your personal AI assistant