Write a Pandas program to calculate the mean score for each different student in Data Frame with Practical Example.
Program Logic:
- Import pandas module in program using import statement
- Import numpy module using import statement
- Create Dictionary object say marks with different set of key value pairs
- Create DataFrame object say result using DataFrame method and pass index as an argument to it
- Print DataFrame ‘result’ using print function
- Calculate mean score for each student using mean function and set attribute axis to 1
- Display mean score of each student using print function.
Below is implementation code /Source code:
import pandas as pd
import numpy as np
marks = { "English" :[67,89,90,55],
"Maths":[55,67,45,56],
"IP":[66,78,89,90],
"Chemistry" :[45,56,67,65],
"Biology":[54,65,76,87]}
result = pd.DataFrame(marks,index=["Athang","Sujata","Sushil","Sumedh"])
print("******************Marksheet****************")
print(result)
print("\nMean score for each different student in data frame:")
print(result.mean(axis=1))
Below is Output:
*****************Marksheet**************** English Maths IP Chemistry Biology Athang 67 55 66 45 54 Sujata 89 67 78 56 65 Sushil 90 45 89 67 76 Sumedh 55 56 90 65 87 Mean score for each different student in data frame: Athang 57.4 Sujata 71.0 Sushil 73.4 Sumedh 70.6 dtype: float64
Below is Snapshot of executable code with output:


You can also Check
- Write a program to create Pandas series from dictionary of values and nd array.
- Write a program to perform mathematical operation on two Pandas series object.
- Write a program to create data frame quarterly sales where each row contain the item category, item name and expenditure. Group the row by the category and print the total expenditure per category.
- Write a program to create data frame based on e-commerce data and generate descriptive statistics.
- Write a program to create data frame for examination result and display row labels, column labels data types of each column and the dimensions.
<