简单python脚本

python脚本

1.需求1

分析文本里面的数据,文本文件太大了,无法用optepad++打开

# coding=utf-8
import time

start=time.time()
filename = 'a.datconv.txt' # txt文件和当前脚本在同一目录下,所以不用写具体路径
data = []
with open(filename, 'r') as file_to_read:
    while True:
        line = file_to_read.readline() # 整行读取数据
        if not line:
          print('read end!!!')
          break
        #print(line)
        p_tmp= [float(i) for i in line.split()] # 将整行数据分割处理
        #列表生成,转化为浮点数
        data.append(p_tmp[4])

#print(data)
f1 = open("write.txt", 'w')
for i in range(len(data)):#遍历,从头到尾
    if data[i]>11 or data[i]<8:
        f1.write(str(i) + ":" + str(data[i]) + "\n")#写入文件
f1.close()

end=time.time()
print(end-start)

2.需求2

提取时间戳,另存为csv文件,用excel打开,做差值(=A2-A1),然后插入图表,分析数据

# coding=utf-8
import time

start=time.time()
filename = 'ReceivedTofile-COM17-2021_7_20_19-20-54.DATconv.txt' # txt文件和当前脚本在同一目录下,所以不用写具体路径
data = []
with open(filename, 'r') as file_to_read:
    while True:
        line = file_to_read.readline() # 整行读取数据
        if not line:
          print('read end!!!')
          break
        #print(line)
        p_tmp= [float(i) for i in line.split()] # 将整行数据分割处理
        #列表生成,转化为浮点数
        data.append(p_tmp[0])

print(data)
print(len(data))
f1 = open("write.csv", 'w')
for i in range(len(data)):
    f1.write( str(data[i]) + "\n")
f1.close()


end=time.time()
print(end-start)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值