Print Page   |   Sign In   |   Register
Read CSV with Date/Time and numeric data
Moderator(s):
Thread Score:
Page 1 of 1
Thread Actions

6/26/2011 at 5:23:55 AM GMT
Posts: 2
Read CSV with Date/Time and numeric data

I'm trying to read in time series data with Date/Time in the first column, and numerical values in several columns to the right. It happens to be in CSV format, but I could easily put in tab format etc. I've tried (read_csv, mfscanf, msscanf, and evstr), but have not been successful. Any guidance would be appreciated.

1/1/2009 9:01,234.6,234.5,324.43,234.3,2342
1/1/2009 9:02,235.6,235.5,325.43,235.3,2343
1/1/2009 9:03,236.6,236.5,326.43,236.3,2344
1/1/2009 9:04,237.6,237.5,327.43,237.3,2345
1/1/2009 9:05,238.6,238.5,328.43,238.3,2346

Thanks, Mike



6/26/2011 at 4:55:45 PM GMT
Posts: 464
RE: Read CSV with Date/Time and numeric data
M. Anderson said:

I'm trying to read in time series data with Date/Time in the first column, and numerical values in several columns to the right. It happens to be in CSV format, but I could easily put in tab format etc. I've tried (read_csv, mfscanf, msscanf, and evstr), but have not been successful. Any guidance would be appreciated.

1/1/2009 9:01,234.6,234.5,324.43,234.3,2342
1/1/2009 9:02,235.6,235.5,325.43,235.3,2343
1/1/2009 9:03,236.6,236.5,326.43,236.3,2344
1/1/2009 9:04,237.6,237.5,327.43,237.3,2345
1/1/2009 9:05,238.6,238.5,328.43,238.3,2346

Thanks, Mike


-->a = read_csv('d:\text.txt',',')
 ans  =
 
!1/1/2009 9:01  234.6  234.5  324.43  234.3  2342   !
!                                                   !
!1/1/2009 9:02  235.6  235.5  325.43  235.3  2343   !
!                                                   !
!1/1/2009 9:03  236.6  236.5  326.43  236.3  2344   !
!                                                   !
!1/1/2009 9:04  237.6  237.5  327.43  237.3  2345   !
!                                                   !
!1/1/2009 9:05  238.6  238.5  328.43  238.3  2346   !

-->a(1)
 ans  =
 
 1/1/2009 9:01   
 
you can also try http://atoms.scilab.org/toolboxes/csv_readwrite


Allan


6/27/2011 at 5:35:02 AM GMT
Posts: 2

Thanks Allan,

"a(1)" that's all it took for me to realize I could pull the date/time column out independently.In case you're interested, here is how I am extracting the Date/Time info, and the numeric data, and then putting them all into a matirx. A little clunky, but functional.

-Mike

 

 sRaw = read_csv(FileLoc+FileNam) //read time series data into a string matrix
dTSData=zeros(sRaw) //preallocate
for i=1:size(sRaw,1) // loop through each row, extract Date/Time data, convert it to serial timestamps and put it in the first column of Data Matrix
    d = eval(strsplit(a(i,1),['/','/',' ',':']))' //Date/Time is currently in m/d/yyyy h:mm format
    dTSData(i)=datenum(d(3),d(1),d(2),d(4),d(5),0) //put into (y m d h m s) order
end
dTSData(:,2:$)=evstr(sRaw(:,2:$)) //put all remaining columns next to serial timestamps in Data Matrix



Community Search
Sign In


Forgot your password?

Register Now!

Scilab Tips


Privacy Policy © 2014 Equalis LLC Terms of Use