Merging CSV tables with Ruby -
I am attempting to join Ruby with CSV files with Stock Indexes, and there is a surprisingly difficult time Understanding the documentation.
let me read my Ruby script every "Date" column, and Write a new CSV
Bonus: Ideally, I would like to add all other column data ("Open", "High", etc.) to this new CSV. The file is divided by a column, in which for the reference is the filename of the following CSV.
Thanks for any thoughts given on this. What I really want to do, help me understand the meaning of documentation by sitting with Ruby Sensei. How can I use CSV.read () or CSV.foreach (). X |
Fictional:
CSV Read ("Data / Data / DOW.csv"). Output | Returns the end of the output Returns:
[["date", "open", "high", "low", "off", "Volume"], ["2014-07-14", "71.35", "71.52", "70.82", "71.28", "823063.0"], ["2014-07-15", "71.32", "71.76 "," "71.0", "71.28", "813861.0"], ["2014-07-16", "71.34", "71.58", "70.68", "71.02", "843347.0"], ["2014-07 -17 "," 70.54 "," 71.46 "," 70.54 "," 71.13 "," 1303839.0 "], [" 2014-07-18 "," 71.46 "," 72.95 "," 71.09 "," 72.46 ", "1375922.0"], ["2014-07-21", "72.21", "73.46", "71.88", "73.38", "1603854.0"], ["2014-07-22", "73.46", "74.76 "," 73.46 "," 74.57 "," 1335305.0 "], [" 2014-07-23 "," 74.54 "," 75.1 "," 73.77 "," 74.88 "," 1834953.0 "]] < / Pre> How can I identify rows, columns, etc.? I am looking for methods or methods of converting this array to hash. Honestly, a broad theoretical approach will conform to my needs.
I am playing with Ruby and CSV mostly on this day, I can help (even if I'm starting myself), but I do not understand what you want as an output (will be a little example
my_array = [] CSV.foreach ( This example will only load columns "Date", "High" and "Volume" in "my_array". "Data.csv") | Line |
If you Try every column you want:
My_array = [] CSV.foreach ("data.csv") | line | My_array.push (line) expiration If you want to access the array element within the array: < / P>
puts my_array [0] [0] .int # = & gt; "date" puts my_array [1] [0] .field # = & gt; "2014-07-14 " When you want to eventually output, if you are on Windows, you can save it from a command prompt:
My_file.rb> Output_in_text_form.txt
Comments
Post a Comment