没有合适的资源?快使用搜索试试~ 我知道了~
python 处理多行多列多文件的数据 #coding=utf-8 import matplotlib.pyplot as plt filename1 = '02.txt' filename2 = '03.txt' filename3 = 'C05.txt' filename4 = 'CSS.txt' fileA = open(filename4,'w') 写入新文件 X,Y,Z,W,list1,list2,list3,list4,list5 = [],[],[],[],[],[],[],[],[] with open(filename1,'r') as f: lines = f.r
资源推荐
资源详情
资源评论
python 处理多行多列多文件的数据处理多行多列多文件的数据
python 处理多行多列多文件的数据处理多行多列多文件的数据
#coding=utf-8
import matplotlib.pyplot as plt
filename1 = '02.txt'
filename2 = '03.txt'
filename3 = 'C05.txt'
filename4 = 'CSS.txt'
fileA = open(filename4,'w') 写入新文件
X,Y,Z,W,list1,list2,list3,list4,list5 = [],[],[],[],[],[],[],[],[]
with open(filename1,'r') as f:
lines = f.readlines()
for line in lines :
value = [float(s) for s in line.split()] X.append(value[2])
with open(filename2,'r') as f:
lines = f.readlines()
for line in lines :
value = [float(s) for s in line.split()] Y.append(value[2])
with open(filename3,'r') as f:
lines = f.readlines()
for line in lines :
value = [float(s) for s in line.split()] Z.append(value[2])
下列代码为处理列循环数据。以每100个数据循环一次为例:
for j in range(100):
A,B,C,D=0,0,0,0
for n in range(20):
m=j+n*100
A=A+X[m] B=B+Y[m] C=C+Z[m] list1.append(A/20) 本例子为将循环的数据求均值
list2.append(B/20)
list3.append(C/20)
list5.append(j)
fileA.write(str(j)+" "+str(A/20)+" "+str(B/20)+" "+str(C/20)+"")
以下部分为画图的代码
plt.grid(True)
plt.plot(list5,list1,marker='*',markerfacecolor='red',label='γ=0.2')
plt.plot(list5,list2,marker='o',markerfacecolor='blue',label='γ=0.3')
plt.plot(list5,list3,marker='3',markerfacecolor='green',label='γ=0.5')
plt.xlabel('time'+""+'(d)')
plt.ylabel('number')
plt.legend()
plt.title('the person')
plt.show()
以上代码亲自测试过,确保没有任何问题。
作者:薛晓斐
资源评论
weixin_38654415
- 粉丝: 4
- 资源: 1015
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功