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,487
  • 2
  • 20
  • 39
Kristada673
  • 3,512
  • 6
  • 39
  • 93

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,830
  • 5
  • 31
  • 53