Challenge with FasterCSV

J

junkone

HI
How can i define the header to be in the 3row of the the array loaded
After the array is loaded can i redefine the header.

for eg in the following cod
require "faster_csv"
arr_of_arrs = FasterCSV.read("c:\\temp\\QuoteData.dat")
currentPrice=arr_of_arrs.values_at(0)[0][1]
arr_of_arrs.delete_at(0)
arr_of_arrs.delete_at(0)

I dont know how to define the header for the arr_of_arrs. I a unclear
after reading the docs
 
J

James Edward Gray II

HI
How can i define the header to be in the 3row of the the array loaded
After the array is loaded can i redefine the header.

for eg in the following cod
require "faster_csv"
arr_of_arrs = FasterCSV.read("c:\\temp\\QuoteData.dat")
currentPrice=arr_of_arrs.values_at(0)[0][1]
arr_of_arrs.delete_at(0)
arr_of_arrs.delete_at(0)

I dont know how to define the header for the arr_of_arrs. I a unclear
after reading the docs

I'm sorry, but I don't think I understand the question well enough to
answer it. Could you please show a small sample data set and what
you would like to accomplish?

James Edward Gray II
 
J

junkone

James said:
HI
How can i define the header to be in the 3row of the the array loaded
After the array is loaded can i redefine the header.

for eg in the following cod
require "faster_csv"
arr_of_arrs = FasterCSV.read("c:\\temp\\QuoteData.dat")
currentPrice=arr_of_arrs.values_at(0)[0][1]
arr_of_arrs.delete_at(0)
arr_of_arrs.delete_at(0)

I dont know how to define the header for the arr_of_arrs. I a unclear
after reading the docs

I'm sorry, but I don't think I understand the question well enough to
answer it. Could you please show a small sample data set and what
you would like to accomplish?

James Edward Gray II

A sample data is in this link
http://www.geocities.com/murthysuresh/ABC.TXT

I am trying to load this file using
arr_of_arrs = FasterCSV.read("c:\\temp\\QuoteData.dat")

I assign the current price using
currentPrice=arr_of_arrs.values_at(0)[0][1]

I then delete the first two lines of the data as they are not useful
anymore
arr_of_arrs.delete_at(0)
arr_of_arrs.delete_at(0)

Now i want to use the 3rd line that u see in the link as my header for
the csv records.
for eg the Calls should refer to the first column, Last Sale for second
column

I am not sure if this is feasible

Thanks in advance

Seede
 
J

James Edward Gray II

I am not sure if this is feasible

Sure it is. Here's the skeleton code to get you going:

require "faster_csv"

File.open("ABC.TXT") do |file|
current_price = file.gets.parse_csv:)row_sep => "\r\r\n")[1]
file.gets
FCSV(file, :row_sep => "\r\r\n", :headers => true) do |csv|
csv.each do |row|
# ... use current_price and row here ...
end
end
end

You may not need those odd :row_sep settings. The file I downloaded
had very odd line endings, but that may have been a web server or
browser mucking with the data along the way.

Hope that helps.

James Edward Gray II
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Collatz Challenge 1
FasterCSV 2
FasterCSV - varying headers 5
FasterCSV heavy loads? 4
Skipping headers in FasterCSV 9
FasterCSV 1.4.0 -- The Final 1.8 Release 1
fastercsv error 3
FasterCsv writing columns 1

Members online

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,088
Members
47,686
Latest member
scamivo

Latest Threads

Top