Write a Pandas program to calculate the mean score for each different student in DataFrame.
Example 1:
Input: DataFrame with 'score' column for each student Output: Mean 'score' for each student
Example 2:
Input: DataFrame with 'score' column for each student Output: Mean 'score' for each student
Use the pandas DataFrame mean() function.
import pandas as pd def mean_score(df): return df['score'].mean() df1 = pd.DataFrame({'name': ['Tom', 'Jack', 'Steve', 'Ricky'], 'score': [85, 90, 87, 91]}) df2 = pd.DataFrame({'name': ['Adam', 'Eve', 'Stark', 'Rogers'], 'score': [88, 92, 95, 97]}) print(mean_score(df1)) print(mean_score(df2))
Unlock AI & Data Science treasures. Log in!