LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

delete column in csv

Solved!
Go to solution

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.

0 Kudos
Message 1 of 5
(3,962 Views)

You will need to read in the entire CSV into arrays and delete the colum you want.  Then resave the data into a CSV.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 5
(3,956 Views)

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.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
0 Kudos
Message 3 of 5
(3,943 Views)
Solution
Accepted by topic author Curtis235

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.

Message 4 of 5
(3,933 Views)

Thank you!!

0 Kudos
Message 5 of 5
(3,903 Views)