title: Sort row of a CSV file by first value
body: <p><strong>Stock data.csv</strong></p>
  
  <pre><code>1425904377,22532.1309,22533.6992,22524.0703,22524.0703,0
  1425904438,22533.4395,22533.4395,22529.2793,22532.2207,0
  1425904499,22531.8809,22536.0801,22531.8809,22533.2793,0
  1425904559,22532.4297,22534.7207,22530.7598,22532.0996,0
  1425904618,22535.7695,22535.9297,22530.6094,22532.2500,0
  1425904679,22536.0703,22539.2598,22535.5605,22535.6094,0
  1425904738,22542.8809,22544.2305,22536.3594,22536.3594,0
  1425904797,22540.6504,22544.0391,22538.5000,22542.9707,0
  1425904857,22545.2891,22552.5098,22538.5898,22538.9004,0
  1425904860,22547.0703,22547.0703,22547.0703,22547.0703,0
  </code></pre>
  
  <p>I have to do two things:</p>
  
  <ol>
  <li>Sort row by <code>timestamp</code> (first value)</li>
  <li>Delete duplicate (key: <code>timestamp</code>)</li>
  </ol>
  
  <p>I tried this, but it isn't working:</p>
  
  <pre><code>my_csv = CSV.read("public/#{symbol}.csv")
  my_csv.sort_by!(&amp;:first)
  
  
  open("public/#{symbol}.csv", 'w') { |f|
    my_csv.each do |row|
      f.puts "#{row.join(",")}"
    end
  }
  </code></pre>