openpyxl模块-----------计算最大值,最小值,平均值
准备数据:
使用Alt= 计算出每列,每行的和,然后计算最后一列,或者最后一行的总和是4375
25行,10列,所以是250个元数据
使用python脚本:
#!/usr/bin/env python
import openpyxl
import statistics as stats
book = openpyxl.load_workbook('C:/Users/Administrator/Desktop/t.xlsx', data_only=True)
sheet = book.active
rows = sheet.rows
values = []
for row in rows:
for cell in row:
values.append(cell.value)
print("Number of values: {0}".format(len(values)))
print("Sum of values: {0}".format(sum(values)))
print("Minimum value: {0}".format(min(values)))
print("Maximum value: {0}".format(max(values)))
print("Mean: {0}".format(stats.mean(values)))
print("Median: {0}".format(stats.median(values)))
print("Standard deviation: {0}".format(stats.stdev(values)))
print("Variance: {0}".format(stats.variance(values)))
实现效果如下:
G:\Python3.8解释器\python.exe C:/Users/Administrator/PycharmProjects/pythonProject/jisuan.py
Number of values: 250
Sum of values: 4375
Minimum value: 1
Maximum value: 34
Mean: 17.5
Median: 17.5
Standard deviation: 7.777658251137417
Variance: 60.49196787148595
Process finished with exit code 0