04-03-2014 03:08 PM
Does anyone know how to delete one column or change values in that column and leave the rest in a csv file??
Example:
CSV file has 40 columns and 70 rows. To delete a column or change it's values.
Thanks in advance.
Solved! Go to Solution.
04-03-2014 03:26 PM
You will need to read in the entire CSV into arrays and delete the colum you want. Then resave the data into a CSV.
04-03-2014 04:03 PM - edited 04-03-2014 04:04 PM
One thing to also consider if the CSV file is realllllllllly long, you could just create a new secondary/temporary file named "originalfilename_temporary.csv". (Or whatever you please). Then you could loop through and read the original file line-by-line and each iteration crop out the column you don't want and write it to the new file. Then when you are completely done looping, simply delete the original file (assuming you don't want to keep it), and rename the new/temporary file with the original file name. This will save a lot of memory.
Note1: This will save much memory during execution at the expense of temporarily using a maximum of twice as much disk space. If your disk space AND memory are limited, then you will need a more complex algorithm likely involving file pointers and other annoying things.
Note2: This will only be necessary for super huge csv files. But I've had some datalogs for 72+ hours and they would often overflow my memory if I tried to manipulate them file at a time.
04-03-2014 04:19 PM
Yeah, I made a quick VI that is a combination of the Cross and Happies methods, takes the whole CSV into memory in the form of an array and then passes it out again to another CSV. If you want to perform any changes to the CSV just treat it the same as you would an array as it passes from one CSV to the other.
04-04-2014 09:25 AM
Thank you!!