Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I delete columns from CSV using Ruby?

Tags:

ruby

csv

Looking at the documentation for the CSV library of Ruby, I'm pretty sure this is possible and easy.

I simply need to delete the first three columns of a CSV file using Ruby but I haven't had any success getting it run.

like image 811
Justin Avatar asked Feb 07 '12 21:02

Justin


1 Answers

csv_table = CSV.read(file_path_in, :headers => true)
csv_table.delete("header_name")
csv_table.to_csv # => The new CSV in string format

Check the CSV::Table documentation: http://ruby-doc.org/stdlib-1.9.2/libdoc/csv/rdoc/CSV/Table.html

like image 147
fguillen Avatar answered Nov 14 '22 09:11

fguillen