python与数学建模------excel数据处理

本次给大家分享一个我们在数学建模中用到的各种方法
用一下的方式,就可以遍历出文件夹下所有的excel所有的一列数据的所有的数据,然后求一下均值,放在一个新的excel表中

import os
import numpy as np
import xlwt

def RSPR_juzhi():
    list1 = []
    path_f = 'F:/建模/建模/建模/train_set'
    flines = os.listdir(path_f)
    for fline in flines:
        list2 = []
        fopen1 = open(path_f + '/' + str(fline), 'r')
        fopen = fopen1.readlines()
        for line in fopen[1:]:
            f = line.strip().split(',')[-1]
            list2.append(float(f))
        RSRP_mean = np.mean(list2)

        list1.append(RSRP_mean)
    #print(list1, len(list1))
    #a=numpy.cov(,list1)
    f = xlwt.Workbook() #创建工作薄
    sheet1 = f.add_sheet(u'sheet1',cell_overwrite_ok=True) #创建sheet
    j = 0
    for i in list1:
        sheet1.write(j,0,i) #循环写入 竖着写
        j=j+1
    f.save('F:text123.xls')#保存文件
RSPR_juzhi()
  • 3
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值