04-05-2019 02:40 PM
In the attached VI, I have a CSV file that contains a Time Stamp with "," in the first column. When I try to generate the array from the original file, I get two extra columns with part of the date occupying the following columns because of the ","s in the Time Stamp column. Is there a simple solution to parse the date correctly to be limited to the first column and not be split up into 3 columns as in the attached VI?
Note that this is a snippet of the full data file. There are thousands of rows.
Thanks for your help and time.
Solved! Go to Solution.
04-05-2019 02:54 PM
The "short" answer....use a "short" date when writing the datestamp to the CSV file.
04-05-2019 02:56 PM
Read the first row separately and parse.
Read the remainder and parse. Work with the first 3 columns to merge them into one deleting the other 2.
Put row 1 with that array.
04-05-2019 03:11 PM
I came up with this as per your suggestion:
Is this what you meant? If so, can this be simplified?
Thanks!
04-05-2019 03:33 PM
After you get passed the first line (headers), you can use Scan From String to get the values into usable numbers (if that is desirable for you).
04-05-2019 03:43 PM - edited 04-05-2019 03:44 PM
You can try this, do not know if it is more efficient, but it is a bit more compact.
mcduff
04-06-2019 02:13 PM
As you undoubtedly know, a CSV (Comma-Separated Values) file uses commas to separate fields. If your data consists of a TimeStamp that has exactly two embedded commas and N other numeric fields (all comma-separated), then (as you note) you'll get the Time information returned as three fields followed by the N Data Fields.
Rather than trying to re-invent the Parse, what I would recommend is to take your (3+N)-column 2D array and pass it through a For loop (which treats the rows one at a time). Split out the first three (Time-stamp) entries, recombine them by adding the commas back in (giving you back your TimeStamp), then "do something intelligent" with the TimeStamp to create a (1+N)-column row consisting of TimeStamp value + N data values. I'm being a bit vague here as I don't know if you are trying to read the CSV file as text or numerics, so don't know how you want to express the TimeStamp data (if everything is text, then the fix is almost trivial -- you can combine the three sub-strings with a single Format into String function with three string inputs and a Format String of $s,$s,$s (three strings, separated by the "missing" commas).
Bob Schor