1 Star 0 Fork 0

坚持不懈的大白/Python 测试

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
5.数据统计和分析报表任务.py 2.43 KB
一键复制 编辑 原始数据 按行查看 历史
liuze 提交于 1年前 . test
import xlrd
xls = xlrd.open_workbook(filename='./datas/1.xls')
sheet = xls.sheets()[0]
# a
sum_people = sheet.nrows - 1
print(f'表格中有{sum_people}人')
# 所有行数减去 列名称哪一行
# b
_str = '134.135.136.137.138.139.147.150.151.152.157.158.159.178.182.183.184.187.188.1703.1705.1706'
# 移动网络
_str2 = '130.131.132.145.155.156.175.176.185.186.1704.1707.1708.1709.171'
# 联通网络
_str3 = '133.149.153.173.177.180.181.189.1700.1701.1702'
# 电信网络
map = {}
for e in _str.split('.'):
map[e] = True
map2 = {}
for e in _str2.split('.'):
map2[e] = True
map3 = {}
for e in _str3.split('.'):
map3[e] = True
arr4 = sheet.col_values(colx=5,start_rowx=1)
# 取第6列数据 ,从第一行数据开始
num1,num2,num3 = 0,0,0
for e in arr4:
_strLen3 = e[:3]
_strLen4 = e[:4]
# 取前3个字符 和 前4个字符
if map.get(_strLen3,False) or map.get(_strLen4,False):
num1 += 1
if map2.get(_strLen3, False) or map2.get(_strLen4, False):
num2 += 1
if map3.get(_strLen3,False) or map3.get(_strLen4,False):
num3 += 1
print('移动:{}人 联通:{}人 电信:{}人'.format(num1,num2,num3))
print('移动:{:.2f}% 联通:{:.2f}% 电信:{:.2f}%'.format(num1/sum_people,num2/sum_people,num3/sum_people))
# c
arr5 = sheet.col_values(colx=8,start_rowx=1)
maleNum = 0
# 男性
womanNum = 0
# 女性
for e in arr5:
maleNum += 1 if e == '男' else 0
womanNum += 1 if e == '女' else 0
print(f'男:{maleNum}人,女:{womanNum}人')
# d
arr6 = sheet.col_values(colx=7,start_rowx=1)
num45 = 0
# 年龄超过45岁
for e in arr6:
# e 为 浮点型float
if int(e) > 45:
num45 += 1
print(f'年龄超过45岁的人数有:{num45}人')
# e
arr7 = sheet.col_values(colx=11,start_rowx=1)
num8000 = 0
num3000 = 0
for e in arr7:
# e 为 浮点型float
if int(e) > 8000:
num8000 += 1
if int(e) < 3000:
num3000 += 1
print(f'薪资超过8000的人数有:{num8000}人,低于3000的人数有:{num3000}人')
# f
arr8 = sheet.col_values(colx=13,start_rowx=1)
num4 = 0
# 传媒人数
for e in arr8:
if e.strip().find('传媒') != -1:
num4 += 1
print(f'传媒人数为:{num4}人')
# g
arr8 = sheet.col_values(colx=9,start_rowx=1)
num5 = 0
for e in arr8:
for e2 in ['黑龙江','北京','四川','福建']:
if e.strip().find(e2) !=-1:
num5 += 1
break
print(f'高危地区人数为:{num5}人')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/il_li/python-testing.git
git@gitee.com:il_li/python-testing.git
il_li
python-testing
Python 测试
master

搜索帮助