Generation

generate functionWed, 18 Jan 2023

There is a Pandas dataframe in this format: id title rating 0 Pulp Fiction (1994) 5.0 1 Three Colors: Red (Trois couleurs: Rouge) (1994) 3.5 2 Three Colors: Blue (Trois couleurs: Bleu) (1993) 5.0 3 Underground (1995) 5.0 4 Singing in the Rain (1952) 3.5 5 Dirty Dancing (1987) 4.0 6 Delicatessen (1991) 3.5 7 Ran (1985) 3.5 8 The Seventh Seal (1957) 5.0 9 Bridge Over the River Kwai (1957) 4.0 Write a function that will pull the year of the movie from its title and add it to the "year" column

def get_year(title): return int(title.split()[-1][1:-1]) df['year'] = df['title'].apply(get_year)

Questions about programming?Chat with your personal AI assistant