Instagram
youtube
Facebook
Twitter

Compute the Standard Deviation of a Column in a Pandas DataFrame

Compute the Standard Deviation of a Column in a Pandas DataFrame

Short Description of the Program:
This program calculates the standard deviation of values in the 'Age' column using the .std() method.

Explanation:

  • df['Age'] selects the Age column from the DataFrame.
     
  • .std() computes the standard deviation, which shows how spread out the ages are around the mean.
     
  • Useful for understanding variability in the data.

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)

std_age = df['Age'].std()

print("Standard Deviation of Age:", std_age)