Yesterday I asked the first question in stackoverflow and was despised... This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form "...
The problem is as follows:
I have a CSV file with header. I need to update all values in a specific column but keep the header, and then save the file. How can I do it via CSV library?
Require 'csv' file _ name = "path/to/file.csv" CSV. foreach (file_name, {: headers => true}) Do | row | puts row [4] endarr = [] # CSV. foreach (file_name, {: headers => true}) {| row | arr <row} arr. each do | row [4]. replace ("new program name") end # Puts arr # CSV. open (file_name, "WB", {: headers => true}) Do | CSV <["your", "Header", "value"] arr. each {| row | CSV <row} end # CSV. foreach (file_name, {: headers => true}) Do | row | puts row [4] End