How to calculate basic statistical values using Python?
Python offers multiple methods to calculate basic statistical values, here are some common ones:
- numerical data
- calculate the average
- Calculate the middle value
- find the most frequently occurring value
- Calculate the difference between the actual value and the expected value.
- standard deviation()
- 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)
- calculate the average
- Find the middle value in a dataset
- find the most frequently occurring value
- variable()
- 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)
- Calculate the average value
- Find the middle value of a set of numbers.
- Determine the most frequently occurring value.
- variable()
- 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.