How to calculate basic statistical values using Python?

Python offers multiple methods to calculate basic statistical values, here are some common ones:

  1. numerical data
  2. calculate the average
  3. Calculate the middle value
  4. find the most frequently occurring value
  5. Calculate the difference between the actual value and the expected value.
  6. standard deviation()
  7. data analysis
import statistics

data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

mean = statistics.mean(data)
median = statistics.median(data)
mode = statistics.mode(data)
variance = statistics.variance(data)
stdev = statistics.stdev(data)

print("平均值:", mean)
print("中位数:", median)
print("众数:", mode)
print("方差:", variance)
print("标准差:", stdev)
  1. calculate the average
  2. Find the middle value in a dataset
  3. find the most frequently occurring value
  4. variable()
  5. standard deviation()
import numpy as np

data = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

mean = np.mean(data)
median = np.median(data)
mode = np.mode(data)
variance = np.var(data)
stdev = np.std(data)

print("平均值:", mean)
print("中位数:", median)
print("众数:", mode)
print("方差:", variance)
print("标准差:", stdev)
  1. Calculate the average value
  2. Find the middle value of a set of numbers.
  3. Determine the most frequently occurring value.
  4. variable()
  5. calculate the standard deviation
import pandas as pd

data = pd.Series([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

mean = data.mean()
median = data.median()
mode = data.mode()
variance = data.var()
stdev = data.std()

print("平均值:", mean)
print("中位数:", median)
print("众数:", mode)
print("方差:", variance)
print("标准差:", stdev)

These methods offer various ways of calculation and functions, allowing one to choose the appropriate method based on specific needs to calculate basic statistical values.

bannerAds