Python中有很多用于統(tǒng)計(jì)的函數(shù)和模塊,常用的統(tǒng)計(jì)函數(shù)包括sum、mean、median、mode、variance、standard deviation等。以下是一些常用的統(tǒng)計(jì)函數(shù)的使用方法:
numbers = [1, 2, 3, 4, 5]
total = sum(numbers)
print(total) # 輸出:15
import statistics
numbers = [1, 2, 3, 4, 5]
average = statistics.mean(numbers)
print(average) # 輸出:3
import statistics
numbers = [1, 2, 3, 4, 5]
middle = statistics.median(numbers)
print(middle) # 輸出:3
import statistics
numbers = [1, 2, 3, 3, 4, 5]
most_common = statistics.mode(numbers)
print(most_common) # 輸出:3
import statistics
numbers = [1, 2, 3, 4, 5]
variance = statistics.variance(numbers)
print(variance) # 輸出:2.5
import statistics
numbers = [1, 2, 3, 4, 5]
std_deviation = statistics.stdev(numbers)
print(std_deviation) # 輸出:1.5811388300841898
需要注意的是,statistics是Python的內(nèi)置模塊,需要使用import語句將其導(dǎo)入才能使用其中的函數(shù)。另外,還可以使用numpy、pandas等第三方庫進(jìn)行更復(fù)雜的統(tǒng)計(jì)分析。