2022/06/12-2022/06/14 Python处理数据
2022.06.12
import csv,sys,os import matplotlib.pyplot as plt def read(filename): # filename='Tcam V5 5.csv' csv_reader = csv.reader(open(filename,encoding='utf-8')) ls1 = [205+66*i for i in range(31)] ls2 = [214+66*i for i in range(31)] n = 0 flag = False tmp,res = [],[] for row in csv_reader: n += 1 if n > 2205: break if n in ls1: # print(row[2]) flag = True if n-1 in ls2: flag = False # print(sum(tmp)/len(tmp)) res.append(sum(tmp)/len(tmp)) tmp = [] if flag: tmp.append(float(row[3])) with open(filename+'.dat','w') as f: for i in res: f.write(str(i) + '\n') return res # filename='Tcam V5 5.csv' # print(read(filename)) for i in os.listdir(): tmp = i.split() # print(tmp) if tmp[-1].split('.')[-1] == 'csv' and tmp[0] == 'Tcam': read(i)
2022.06.14
import matplotlib.pyplot as plt import numpy as np import xlrd,sys,os import xlwt as ExcelWrite import xlsxwriter filename = 'Eng_Sweep_IdVg_220609_095907.xlsx' data = xlrd.open_workbook(filename) # print(data.sheet_names()) table = data.sheet_by_name('Sheet1') # V = table.row_values(2) V = table.col_values(2) I = table.col_values(3) tmp = 7 ls = [] for i in range(1,513): ls.append(tmp) if i%8 == 0: tmp += 108 else: tmp += 114 # print(ls) resV1,resV2,resV3 = [],[],[] resV4,resV5,resV6 = [],[],[] resV7,resV0 = [],[] resI1,resI2,resI3 = [],[],[] resI4,resI5,resI6 = [],[],[] resI7,resI0 = [],[] for i,j in enumerate(ls): if i%8 == 0: resV0.append(V[j-1:j+50]) resI0.append(I[j-1:j+50]) elif i%8 == 1: resV1.append(V[j-1:j+50]) resI1.append(I[j-1:j+50]) elif i%8 == 2: resV2.append(V[j-1:j+50]) resI2.append(I[j-1:j+50]) elif i%8 == 3: resV3.append(V[j-1:j+50]) resI3.append(I[j-1:j+50]) elif i%8 == 4: resV4.append(V[j-1:j+50]) resI4.append(I[j-1:j+50]) elif i%8 == 5: resV5.append(V[j-1:j+50]) resI5.append(I[j-1:j+50]) elif i%8 == 6: resV6.append(V[j-1:j+50]) resI6.append(I[j-1:j+50]) elif i%8 == 7: resV7.append(V[j-1:j+50]) resI7.append(I[j-1:j+50]) workbook = xlsxwriter.Workbook('res.xlsx') num = len(resV0)*len(resV0[0]) worksheet0 = workbook.add_worksheet('res0') row,col = 0,0 for i in range(len(resV0)): for j in range(len(resV0[0])): worksheet0.write(row,col,resV0[i][j]) worksheet0.write(row,col+1,resI0[i][j]) row += 1 worksheet1 = workbook.add_worksheet('res1') row,col = 0,0 for i in range(len(resV0)): for j in range(len(resV0[0])): worksheet1.write(row,col,resV1[i][j]) worksheet1.write(row,col+1,resI1[i][j]) row += 1 worksheet2 = workbook.add_worksheet('res2') row,col = 0,0 for i in range(len(resV0)): for j in range(len(resV0[0])): worksheet2.write(row,col,resV2[i][j]) worksheet2.write(row,col+1,resI2[i][j]) row += 1 worksheet3 = workbook.add_worksheet('res3') row,col = 0,0 for i in range(len(resV0)): for j in range(len(resV0[0])): worksheet3.write(row,col,resV3[i][j]) worksheet3.write(row,col+1,resI3[i][j]) row += 1 worksheet4 = workbook.add_worksheet('res4') row,col = 0,0 for i in range(len(resV0)): for j in range(len(resV0[0])): worksheet4.write(row,col,resV4[i][j]) worksheet4.write(row,col+1,resI4[i][j]) row += 1 worksheet5 = workbook.add_worksheet('res5') row,col = 0,0 for i in range(len(resV0)): for j in range(len(resV0[0])): worksheet5.write(row,col,resV5[i][j]) worksheet5.write(row,col+1,resI5[i][j]) row += 1 worksheet6 = workbook.add_worksheet('res6') row,col = 0,0 for i in range(len(resV0)): for j in range(len(resV0[0])): worksheet6.write(row,col,resV6[i][j]) worksheet6.write(row,col+1,resI6[i][j]) row += 1 worksheet7 = workbook.add_worksheet('res7') row,col = 0,0 for i in range(len(resV0)): for j in range(len(resV0[0])): worksheet7.write(row,col,resV7[i][j]) worksheet7.write(row,col+1,resI7[i][j]) row += 1 workbook.close()