URN Logo
UNIX Resources » Linux » China Linux Forum » Python 编 程 » 4 » 每60行求平均
announcement 声明: 本页内容为中国Linux论坛的内容镜像,文章的版权以及其他所有的相关权利属于中国Linux论坛和相应文章的作者,如果转载,请注明文章来源及相关版权信息。
Resources
China Linux Forum(finished)
Linux Forum(finished)
FreeBSD China(finished)
linuxforum.net
  业界新闻与评论
  自由软件杂谈
  IT 人生
  Linux软件快递
  翻译作坊
  Linux图书与评论
  GNU Emacs/XEmacs
  Linux 中文环境和中文化
  Linux桌面与办公软件
  Linux 多媒体与娱乐版
  自由之窗Mozilla
  笔记本电脑上的Linux
  Gentoo
  Debian 一族
  网络管理技术
  Linux 安装与入门
  WEB服务器和FTP服务器
  域名服务器和邮件服务器
  Linux防火墙和代理服务器应用
  文件及打印服务器
  技术培训与认证
  Linux内核技术
  Linux 嵌入技术
  Linux设备驱动程序
  Linux 集群技术
  LINUX平台数据库
  系统和网络安全
  CPU 与 编译器
  系统计算研究所专栏
  Linux下的GUI软件开发
  C/C++编程版
  PHP 技 术
  Java&jsp技术
  Shell编程技术
  Perl 编 程
  Python 编 程
  XML/Web Service 技术
  永远的Unix
  FreeBSD世界
   
每60行求平均
每60行求平均 - happyhappy [2005-12-03 19:51 | 382 byte(s)]
 
Re: 每60行求平均 - happyhappy [2005-12-12 09:47 | 2,362 byte(s)]
 
Re: 每60行求平均 - passworld [2005-12-03 21:29 | 26 byte(s)]
 
Re: 每60行求平均 - passworld [2005-12-03 21:26 | 18 byte(s)]
 
Subject: 每60行求平均
Author: happyhappy    Posted: 2005-12-03 19:51    Length: 382 byte(s)
[Original] [Print] [Top]
.091
.09
.095
.09
.09
.092
.092
.092
.087
.09
.09
.092
.093
.092
.089
.093
........
这样一个文件,一秒种一个数据,要求每小时的平均值,本来想把整列读到列表中,再利用[0:59]求和再平均,可是总是把所有的数据都读出来,split列表也不行,怎办啊?
[Original] [Print] [Top]
Subject: Re: 每60行求平均
Author: passworld    Posted: 2005-12-03 21:26    Length: 18 byte(s)
[Original] [Print] [Top]
你的码?
----
[Original] [Print] [Top]
Subject: Re: 每60行求平均
Author: passworld    Posted: 2005-12-03 21:29    Length: 26 byte(s)
[Original] [Print] [Top]
str.splitlines()
----
[Original] [Print] [Top]
Subject: Re: 每60行求平均
Author: happyhappy    Posted: 2005-12-12 09:47    Length: 2,362 byte(s)
[Original] [Print] [Top]
import sys,string,math
fr=open("e:/zwxdata/200509/2005_09_01.txt")
fw=open("e:/zwxdata/2out2005_09_01.txt","w")
line=0
c1=[]
c2=[]
count1=1
count2=1
sum1=0
sum2=0
avarage1=1
average2=1

for i in fr.readlines():
line=line+1
for a1 in range(1,60):
if line==a1:
line21=str.split(i)
line31=float(str(line21[4]))
c1 =[line31]

for m1 in c1:
count1+=1
sum1=sum1+m1
average1=sum1/count1
for a2 in range(60,120):
if line==a2:
line22=str.split(i)
line32=float(str(line22[4]))
c2 =[line32]
for m2 in c2:
sum2=sum2+m2
count2+=1
average2=sum2/count2
print average1
print average2

fr.close()
fw.close()
我这个文件要做第4列每隔60个数的平均值,这里只作了2个,可以运行了.但要做成函数形式出错了,帮我看看吧
import sys,string,math
fr=open("e:/zwxdata/200509/2005_09_01.txt")
fw=open("e:/zwxdata/42out2005_09_01.txt","w")

line=0
count=1
c=[]
av=0.0
sum=0.0

def average():
for i in fr.readlines():
line+=1
if line==a:
line2=str.split(i)
line3=float(str(line2[4]))
c =[line3]

for m in c:
count=count+1
sum=sum+m
av=sum/count

return av
print av
for a in range(1,60):
ss=average()

[Original] [Print] [Top]
« Previous thread
python httplib.respose.read()怎样接收gzip数据
Python 编 程
4
Next thread »
如何用python下载页面内容,该页面需要用户登录才能看到??
     

Copyright © 2007 UNIX Resources Network, All Rights Reserved.      About URN | Privacy & Legal | Help | Contact us
备案序号: 京ICP备05006143    webmaster: webmaster@unixresources.net
This page created on 2008-07-17 04:10:57, cost 0.05924391746521 ms.