# this code process the one minutes cpc data and convert it to each seconds
import xlrd, xlwt, datetime
from array import array
fileName1 = '06082015.xlsx'
f1WorkBook = xlrd.open_workbook(fileName1)
#check sheet names
sheetName = f1WorkBook.sheet_names()
# select the first sheet
f1Sheet1 = f1WorkBook.sheet_by_index(0)
sn = 19
en = 147
#copy and paste the header lines, row 0 to 17
header = [f1Sheet1.row(r) for r in range(18)]
#header = [f1Sheet1.cell_value(row, col) for col in range(2) for row in range(18)]
print header[0]
### ----------This section deals with header---------------------------
newWorkBook = xlwt.Workbook()
newsheet = newWorkBook.add_sheet('processed_'+fileName1[0:8])
for rowIndex, rowValue in enumerate(header):
for colIndex, cellValue in enumerate(rowValue):
newsheet.write(rowIndex, colIndex, cellValue.value)
###-------This part deals with the time column---------------------------------
time = [f1Sheet1.cell_value(row, col) for col in range(2) for row in range(sn-1,en)]
newTime = [0]*((en-sn)*60) # create an empty vector
newTime[0] = time[0]
print newTime[0]
for i in range(0, en-sn):
for j in range(0,60):
#if j+60*i <70: font="">70:>
# print j+60*i
newTime[j+60*i] = newTime[0]+(j+60*i)/(1440*60.0)
for rowIndex in range(18, 18+(en-sn)*60):
#print rowIndex
newsheet.write(rowIndex, 0, newTime[rowIndex-18])
###---------This section deals with the concentrations -----------------------
conc = [f1Sheet1.cell_value(row,col) for col in range(1,2) for row in range(sn-1, en)]
newConc = [0]*((en-sn)*60)
for i in range(0, en-sn):
for j in range(0,60):
newConc[j+60*i] = conc[i]
for rowIndex in range(18, 18+(en-sn)*60):
newsheet.write(rowIndex, 1, newConc[rowIndex-18])
### ------------------Save file
newWorkBook.save('processed_'+fileName1[0:8]+'.xls')
MATLAB applications, tutorials, examples, tricks, resources,...and a little bit of everything I learned ...
Showing posts with label xlswrite. Show all posts
Showing posts with label xlswrite. Show all posts
Tuesday, September 15, 2015
Wednesday, June 1, 2011
simple data matching by using dataset arrays
Task : There are two Excel files, one contains the sample number and the time of sampling while the other contains the analysis results of each sample. Because the samples were taken in a chronicle order and were analysed in random order, it is kind of time consuming to manually find out each sample's result and put them into one file, especially when dealing with thousands of samples.
Here's a short code I wrote to do this:
% This program search the bag numbers and put the corresponding
% concentration values into the data file.
%% initialization
clear all;
clc;
%% import data
dataf=dataset('xlsfile','back.xls'); %aisle files from field test
concf=dataset('xlsfile','concentration.xls'); %concentration readings from autoTrac
%% determine dataset array size
datafL=length(dataf);
concfL=length(concf);
%% search and match
for i=1 : datafL
for j= 1 : concfL-1
if ( char(dataf.BagNumber(i))==char(concf.BagNumber(j)) )
dataf.Concentration1(i)=concf.Concentration(j);
dataf.Concentration2(i)=concf.Concentration(j+1);
break
end
end
end
%% Output data
export(dataf, 'xlsfile', 'Processed bag files-back.xls')
The dataset array is very power at handling different type of data, including numbers, strings, and even matrix.
To write a dataset array to an Excel file, I need to use export function instead of xlswrite.
Here's a short code I wrote to do this:
% This program search the bag numbers and put the corresponding
% concentration values into the data file.
%% initialization
clear all;
clc;
%% import data
dataf=dataset('xlsfile','back.xls'); %aisle files from field test
concf=dataset('xlsfile','concentration.xls'); %concentration readings from autoTrac
%% determine dataset array size
datafL=length(dataf);
concfL=length(concf);
%% search and match
for i=1 : datafL
for j= 1 : concfL-1
if ( char(dataf.BagNumber(i))==char(concf.BagNumber(j)) )
dataf.Concentration1(i)=concf.Concentration(j);
dataf.Concentration2(i)=concf.Concentration(j+1);
break
end
end
end
%% Output data
export(dataf, 'xlsfile', 'Processed bag files-back.xls')
The dataset array is very power at handling different type of data, including numbers, strings, and even matrix.
To write a dataset array to an Excel file, I need to use export function instead of xlswrite.
Subscribe to:
Posts (Atom)
my-alpine and docker-compose.yml
``` version: '1' services: man: build: . image: my-alpine:latest ``` Dockerfile: ``` FROM alpine:latest ENV PYTH...
-
It took me a while to figure out how to insert a space in Mathtype equations. This is especially useful when you write an equation with mult...
-
In this post, I am trying to solve the problem given in the comments of one of the old post. Here's the problem, if I understand it co...
-
Recently I got a very long column of data and it contains lots of NaN. I found the finite function very useful to help me remove all the NaN...