1

I need to modify some values in some columns of a CSV and after modifying them I need to copy them to a new CSV. For the first column, I do this:

my_csv = CSV.open('MyCSV.csv')
first_column = my_csv.map(&:first)
#do something with them

So, how do I access the other columns since there is no &:second or &:third?

wurde
  • 2,181
  • 1
  • 19
  • 36
Kristada673
  • 3,123
  • 4
  • 28
  • 78

1 Answers1

2

you could also try this:

test1.csv

name,surname,age
em,good,23
cat,cute,40

ruby.rb

require 'csv'

csv = CSV.read('test1.csv', headers: true)
p csv['age'] 

#=> ["23", "40"]
emi
  • 2,641
  • 5
  • 28
  • 52