Instagram
youtube
Facebook
Twitter

Compute the Mean Value of a Column in a Pandas DataFrame

   Compute the Mean Value of a Column in a Pandas DataFrame

    Short Description of the Program:
    This program calculates the mean (average) of the values in the Age column of a Pandas DataFrame.

     Explanation:

  • df['Age'] accesses the 'Age' column.
     
  • .mean() computes the average of all numeric values in that column.
     
  • The result is a single float number representing the mean.

Program:

import pandas as pd

data = {

    'Name': ['Alice', 'Bob', 'Charlie', 'Diana', 'Eva', 'Frank'],

    'Age': [25, 30, 22, 28, 26, 35],

    'Gender': ['Female', 'Male', 'Male', 'Female', 'Female', 'Male'],

    'City': ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix', 'Seattle']

}
df = pd.DataFrame(data)

mean_age = df['Age'].mean()

print("Mean Age:", mean_age)