我有一个 csv 报告,其中有两行标题为“日期”和“客户名称”:
["Date", "Customer_Name"]
["Monday", "John"]
["", "David"]
["", "Sam"]
["", "Kenny"]
["Tuesday", "Mary"]
["", "Jade"]
["", "Lindsay"]
["Wednesday", "Tom"]
["", "Lindon"]
["", "Peter"]
我正在尝试打印一份声明以显示当天的客户是谁,因此它会显示如下:星期一有客户 John、David、Sam 和 Kenny。\n 星期二有 Mary、Jade 和 Lindsay
我的代码是:
require 'csv'
col_date = []
col_name = []
custDate = CSV.foreach("customerVisit.csv") {|row| col_date << row[0]}
customer_name = CSV.foreach("customerVisit.csv") {|row| col_name << row[1]}
print "#{col_date} has customers #{col_name} visited the store."
但我没有得到正确的输出,很可能我是编程新手。请帮助我应该如何达到要求?
["Date", "Monday", nil, nil, nil, "Tuesday", nil, nil, "Wednesday", nil, nil] 有客户 ["Customer_Name", "John", "David", "Sam", “Kenny”、“Mary”、“Jade”、“Lindsay”、“Tom”、“Lindon”、“Peter”] 参观了商店。C02S51D2G8WL:RubySQL
问候