这怎么行不通?CSV 在那里并且有值,我在顶部有“需要“csv”和时间,那里很好。问题似乎与csv.each
实际做任何事情有关。
它返回
=> [] is the most common registration hour
=> [] is the most common registration day (Sunday being 0, Mon => 1 ... Sat => 7)
如果我可以提供更多信息,请告诉我。
@x = CSV.open \
'event_attendees.csv', headers: true, header_converters: :symbol
def time_target
y = []
@x.each do |line|
if line[:regdate].to_s.length > 0
y << DateTime.strptime(line[:regdate], "%m/%d/%y %H:%M").hour
y = y.sort_by {|i| grep(i).length }.last
end
end
puts "#{y} is the most common registration hour"
y = []
@x.each do |line|
if line[:regdate].to_s.length > 0
y << DateTime.strptime(line[:regdate], "%m/%d/%y %H:%M").wday
y = y.sort_by {|i| grep(i).length }.last
end
end
puts "#{y} is the most common registration day \
(Sunday being 0, Mon => 1 ... Sat => 7)"
end
制作所有 'y's '@y's 并没有修复它。
这是我正在使用的 CSV 示例:
,RegDate,first_Name,last_Name,Email_Address,HomePhone,街道,城市,州,邮政编码
1,11/12/08 10:47,Allison,Nguyen,arannon@jumpstartlab.com,6154385000,3155 19th St NW,Washington,DC,20010
2,11/12/08 13:23,SArah,Hankins,pinalevitsky@jumpstartlab.com,414-520-5000,2022 15th Street NW,Washington,DC,20009
3,11/12/08 13:30,Sarah,Xx,lqrm4462@jumpstartlab.com,(941)979-2000,4175 3rd Street North,Saint Petersburg,FL,33703