Research Breakthrough Possible @S-Logix pro@slogix.in

Office Address

Social List

How to Calculate the Measure of Dispersion for a Dataset Using Python

Calculating Dispersion in Python

Condition for Calculating the Measures of Dispersion in a Dataset Using Python

  • Description:
    Dispersion measures the spread or variability of data points around a central value. The common measures of dispersion are:
    • Range: Difference between the maximum and minimum values.
    • Variance: Average of the squared differences from the mean.
    • Standard Deviation: Square root of variance, showing the spread in the same units as the data.
Step-by-Step Process
  • Range:
    Calculate the maximum and minimum values of the dataset, then subtract the minimum value from the maximum value.
  • Variance:
    Calculate the mean of the dataset, subtract the mean from each data point, square the result, and take the average of these squared differences.
  • Standard Deviation:
    Take the square root of the variance.
Sample Source Code
  • # Import necessary libraries
    import pandas as pd

    df = pd.read_csv('/home/soft23/Downloads/company_sales_data.csv')

    print("ORIGINAL DATASET: ")
    print(df)
    print()

    # Variance calculation
    print("VARIANCE OF THE DATASET:")
    print(df.var())
    print()

    # Standard deviation calculation
    print("STANDARD DEVIATION OF THE DATASET:")
    print(df.std())

Screenshots
  • Variance and Standard Deviation Calculation