Python中有很多用于統計的函數和模塊,常用的統計函數包括sum、mean、median、mode、variance、standard deviation等。以下是一些常用的統計函數的使用方法:
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的內置模塊,需要使用import語句將其導入才能使用其中的函數。另外,還可以使用numpy、pandas等第三方庫進行更復雜的統計分析。