我有一個CSV文件蒙山結構如下:爲什麼在讀取CSV文件時有尾部列?
"customer_id";"customer_name";"quantity";
"id1234";"Henry";"15";
與Ruby的標準CSV LIB解析:
csv_data = CSV.read(pathtofile,{
:headers => :first_row,
:col_sep => ";",
:quote_char => '"'
:row_sep => "\r\n" #setting it to "\r" or "\n" results in MalformedCSVError
})
puts csv_data.headers.count #4
我不明白爲什麼解析似乎導致四列雖然文件只包含三個。這不是解析文件的正確方法嗎?
我將刪除尾部;有乾淨的數據可以使用。感謝你的回答。 – Gilles