Generation

generate functionTue, 21 Feb 2023

There is a Pandas dataframe: Last Updated Installs 7479 2010-05-21 100000 7430 2011-01-30 50000 10282 2011-03-16 100000 8418 2011-04-11 5000000 8084 2011-04-16 50000 9067 2011-04-18 50000 5144 2011-05-12 100 7237 2011-06-23 1000 10460 2011-06-26 5000 1544 2011-06-29 1000000 7080 2011-07-10 5000000 8200 2011-09-20 50000 5561 2011-09-22 1000000 Write a function that will create a 'year' column, in which the first 4 characters of the 'Last Updated' column will be added

def year(df): df["year"] = df["Last Updated"].apply(lambda x: x[:4]) return df

Questions about programming?Chat with your personal AI assistant