Generation

generate functionWed, 18 Jan 2023

There is a Pandas dataframe: 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 Singin' in the Rain (1952) 3.5 5 Dirty Dancing (1987) 4.0 6 Delicatessen (1991) 3.5 7 Ran (1985) 3.5 8 Seventh Seal, The (Sjunde inseglet, Det) (1957) 5.0 9 Bridge on the River Kwai, The (1957) 4.0 both titles and ratings in this table are not unique, they are duplicated many times Write a function that groups unique movie titles in one column and displays their average rating in the second column

def group_avg_ratings(df): #your code here df = pd.DataFrame({'id':[0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9], 'title':['Pulp Fiction (1994)','Three Colors: Red (Trois couleurs: Rouge) (1994)','Three Colors: Blue (Trois couleurs: Bleu) (1993)','Underground (1995)','Singin\' in the Rain (1952)','Dirty Dancing (1987)','Delicatessen (1991)','Ran (1985)','Seventh Seal, The (Sjunde inseglet, Det) (1957)','Bridge on the River Kwai, The (1957)','Pulp Fiction (1994)','Three Colors: Red (Trois couleurs: Rouge) (1994)','Three Colors: Blue (Trois couleurs: Bleu) (1993)','Underground (1995)','Singin\' in the Rain (1952)','

Questions about programming?Chat with your personal AI assistant