title: Using Ruby CSV to extract one column
body: <p>I've been trying to work with getting a single column out of a csv file. </p>
  
  <p>I've gone through the documentation, <a href="http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/index.html" rel="noreferrer">http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/index.html</a>
  but still don't really understand how to use it.</p>
  
  <p>If I use <code>CSV.table</code>, the response is incredibly slow compared to <code>CSV.read</code>. I admit the dataset I'm loading is quite large, which is exactly the reason I only want to get a single column from it.</p>
  
  <p>My request is simply currently looks like this</p>
  
  <pre><code>@dataTable = CSV.table('path_to_csv.csv')
  </code></pre>
  
  <p>and when I debug I get a response of </p>
  
  <pre>
  #&lt;CSV::Table mode:col_or_row row_count:2104 &gt;
  </pre>
  
  <p>The documentation says I should be able to use <a href="http://ruby-doc.org/stdlib-1.9.2/libdoc/csv/rdoc/CSV/Table.html#method-i-by_col#by_col-method" rel="noreferrer">by_col()</a>, but when I try to output</p>
  
  <pre><code>&lt;%= debug @dataTable.by_col('col_name or index') %&gt;
  </code></pre>
  
  <p>It gives me "undefined method 'col' error"</p>
  
  <p>Can somebody explain to me how I'm supposed to use CSV? and if there is a way to get columns faster using 'read' instead of 'table'?</p>
  
  <p>I'm using Ruby 1.92, which says that it is using fasterCSV, so I don't need to use the FasterCSV gem. </p>