# CSV question

**URL:** <https://www.ruby-forum.com/t/csv-question/117392>\
**Category:** Ruby\
**Created:** [October 16, 2007, 4:22pm UTC](https://www.ruby-forum.com/t/csv-question/117392 "2007-10-16T16:22:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![harper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5ac83/32.png) [@harper](https://www.ruby-forum.com/u/harper)\
**Post date:** [October 16, 2007, 4:22pm UTC](https://www.ruby-forum.com/t/csv-question/117392/1 "2007-10-16T16:22:09Z")

</div>

hi,

CSV (more specifically FasterCSV) reads the file i provided row by row

FasterCSV.foreach(‘path/to/file.csv’, ‘r’) do |r|  
r # this is an array of a row in the file  
end

but i need to get the array column by column…  
is there a way i can simply do this? (even rotating the excel 90 degrees  
should do the trick as well!)

FasterCSV.foreachcolumn(‘path/to/file.csv’, ‘r’) do |c|  
c # this is an array of a column yay for all and such things  
end

apologize for the redundant question

---

<div class="post-metadata">

**Author:** ![harper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5ac83/32.png) [@harper](https://www.ruby-forum.com/u/harper)\
**Post date:** [October 16, 2007, 4:32pm UTC](https://www.ruby-forum.com/t/csv-question/117392/2 "2007-10-16T16:32:08Z")

</div>

sorry, ignore this post

---

<div class="post-metadata">

**Author:** ![harper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5ac83/32.png) [@harper](https://www.ruby-forum.com/u/harper)\
**Post date:** [October 16, 2007, 4:35pm UTC](https://www.ruby-forum.com/t/csv-question/117392/3 "2007-10-16T16:35:15Z")

</div>

On 10/16/07, Shai R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> CSV (more specifically FasterCSV) reads the file i provided row by row
> 
> FasterCSV.foreach(‘path/to/file.csv’, ‘r’) do |r|  
> r # this is an array of a row in the file  
> end
> 
> but i need to get the array column by column…  
> is there a way i can simply do this? (even rotating the excel 90 degrees  
> should do the trick as well!)

I don’t know if there’s a better way, but you can do this:

a = FasterCSV.parse(File.read(“catalogue.csv”))  
a.transpose.each {|column| …}

but you will have errors if the rows don’t have the same number of  
elements.

Hope this helps,

Jesus.
