Is there a way to skip the first line of a CSV file and make the second line act as the header?
I have a CSV file that has the date on the first row and the headers
I don't think there's an elegant way of doing it, but it can be done:
require "csv"
# Create a stream using the original file.
# Don't use `textmode` since it generates a problem when using this approach.
file = File.open "file.csv"
# Consume the first CSV row.
# `\r` is my row separator character. Verify your file to see if it's the same one.
loop { break if file.readchar == "\r" }
# Create your CSV object using the remainder of the stream.
csv = CSV.new file, headers: true