处理延期比数据并生成频率直方图,并把每个区间赋值为1-10以内数据,自动生成txt文件,方便处理:
【2019年华中杯数学建模B题数据处理代码】.py
import pandas as pd# 柱形图-折线图from pyecharts import Bar, Line, Overlapimport numpy as npimport matplotlib.pyplot as plt#读取按季度分的表格并统计每个区间的个数def readExcel(x):yy = []a1 = [];a11 = [];a12 = [];a13 = []a2 = [];a3 = [];a4 = [];a5 = [];a6 = []for i in range(len(x['延期比'])):# if x['延期比'][i] >= 0 and x['延期比'][i] < 0.01:#a1.append(x['延期比'][i])#0-0.01# if x['延期比'][i] == 0:## a11.append(x['延期比'][i])#a11.append(1)if x['延期比'][i] > 0 and x['延期比'][i] < 0.001:# a12.append(x['延期比'][i])a12.append(1)elif x['延期比'][i] >= 0.001 and x['延期比'][i] < 0.01:# a13.append(x['延期比'][i])a13.append(2)elif x['延期比'][i] >= 0.01 and x['延期比'][i] < 0.02:# a2.append(x['延期比'][i])a2.append(3)elif x['延期比'][i] >= 0.02 and x['延期比'][i] < 0.1:# a3.append(x['延期比'][i])a3.append(4)elif x['延期比'][i] >= 0.1 and x['延期比'][i] < 0.2:# a4.append(x['延期比'][i])a4.append(5)elif x['延期比'][i] >= 0.2 and x['延期比'][i] < 0.35:# a5.append(x['延期比'][i])a5.append(6)elif x['延期比'][i] >= 0.35 and x['延期比'][i] <= 0.5:# a6.append(x['延期比'][i])a6.append(7)# yy.append(len(a11))yy.append(len(a12))yy.append(len(a13))yy.append(len(a2))yy.append(len(a3))yy.append(len(a4))yy.append(len(a5))yy.append(len(a6))return yy#生成matlab需要数据def createMatl(myData):print(myData)my_list = []for i in range(myData[0]):my_list.append(1)for i in range(myData[1]):my_list.append(2)for i in range(myData[2]):my_list.append(3)for i in range(myData[3]):my_list.append(4)for i in range(myData[4]):my_list.append(5)for i in range(myData[5]):my_list.append(6)for i in range(myData[6]):my_list.append(7)print(my_list)return my_list# with open('all_data.txt','w') as f:#f.write(str(my_list))def createChart(my_list):xx = [1,2,3,4,5,6,7]bar = Bar("柱形图-折线图")bar.add('bar', xx, my_list)line = Line()line.add('line', xx, my_list)overlap = Overlap()overlap.add(bar)overlap.add(line)overlap.show_config()overlap.render(path='第二题延期比.html')def main():df = pd.read_excel('附件二.xlsx',sheet_name='汇总')list = readExcel(df)#createChart(list)#createMatl(list)list = createMatl(list)# 求均值arr_mean = np.mean(list)# 求方差arr_var = np.var(list)# 求标准差arr_std = np.std(list)print(arr_mean)print(arr_var)print(arr_std)# plt.style.use('seaborn-white')# # 最基本的频次直方图命令# plt.hist(list)# plt.show()if __name__ == '__main__':main()
.py
import pandas as pd# 柱形图-折线图from pyecharts import Bar, Line, Overlap#读取按季度分的表格并统计每个区间的个数def readExcel(x):yy = []a1 = [];a2 = [];a3 = [];a4 = [];a5 = []a6 = [];a7 = [];a8 = [];a9 = [];a10 = []for i in range(len(x['延期比'])):if x['延期比'][i] >= 0 and x['延期比'][i] < 0.1:# a1.append(x['延期比'][i])a1.append(1)elif x['延期比'][i] >= 0.1 and x['延期比'][i] < 0.2:# a2.append(x['延期比'][i])a2.append(2)elif x['延期比'][i] >= 0.2 and x['延期比'][i] < 0.3:#a3.append(x['延期比'][i])a3.append(3)elif x['延期比'][i] >= 0.3 and x['延期比'][i] < 0.4:# a4.append(x['延期比'][i])a4.append(4)elif x['延期比'][i] >= 0.4 and x['延期比'][i] < 0.5:# a5.append(x['延期比'][i])a5.append(5)elif x['延期比'][i] >= 0.5 and x['延期比'][i]
- 版权价值大涨,女足世界杯或成最贵女子体育赛事 女足吉尼斯记录
- 2019年的上海夏天:总降水量创历史之最,一季下出一年的雨 上海温差历史之最
- 数届女足世界杯之最,赛事奖金总额达到1.52亿 比赛奖金数历史之最
- 国内保温杯什么牌子好?十大排行榜,国货品牌占据一半! 中国十大保温杯品牌
- 超强的“世界第一肝帝”,获白金奖杯2700个,五次吉尼斯世界纪录 吉尼斯记录奖杯
- Doa2石油杯TS夺冠,独得500w美元!TL解锁五亚成就合成不朽盾? doa2历史之最
- 保温杯的盖子缝怎么洗,保温杯盖子怎么拆开
- 葡萄牙对西班牙世界杯
- 趣评世界杯别再说“美中不足”:这不是“自慰”,而是自欺 8 历史之最的梗
- 本人心目中的世界杯历史十大经典比赛 世界杯十大经典比赛