hhhhh耗 2018-05-19 05:21 采纳率: 14.3%
浏览 4648
已采纳

Python疑问,求平均值问题

105.408635, 109.058062
109.711955, 107.612010
106.770910, 107.178111
104.902315, 108.942544
106.429432, 109.986264
106.350715, 108.745940
107.208566, 106.724891
105.758081, 107.954024
106.635802, 105.702770
109.028467, 105.940024
104.741757, 109.545083
104.469050, 105.768578
105.860169, 106.943419
104.190133, 108.945727
108.427905, 107.905775
105.105144, 108.668921
105.584954, 110.006551
105.130636, 105.577014
106.174433, 106.636557
107.386285, 108.500267
107.742580, 110.253006
107.594896, 106.710349
109.138761, 106.629520
...... .......
Python读取txt文件,然后咋将第一列数字求平均值啊

  • 写回答

4条回答 默认 最新

  • threenewbee 2018-05-19 07:40
    关注
     import sys
    
    sum = 0
    cnt = 0
    f = open('1.txt', 'r')
    s = f.readline()
    while (s):
        sum = sum + float(s.split(",")[0])
        cnt = cnt + 1
        s = f.readline()
    print(sum / cnt)
    f.close()
    
    
    106.51093830434785
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 系统 24h2 专业工作站版,浏览文件夹的图库,视频,图片之类的怎样删除?
  • ¥15 怎么把512还原为520格式
  • ¥15 MATLAB的动态模态分解出现错误,以CFX非定常模拟结果为快照
  • ¥15 求高通平台Softsim调试经验
  • ¥15 canal如何实现将mysql多张表(月表)采集入库到目标表中(一张表)?
  • ¥15 wpf ScrollViewer实现冻结左侧宽度w范围内的视图
  • ¥15 栅极驱动低侧烧毁MOSFET
  • ¥30 写segy数据时出错3
  • ¥100 linux下qt运行QCefView demo报错
  • ¥50 F1C100S下的红外解码IR_RX驱动问题