0
这是怎么回事? CSV在那里,有价值,我有“需要”csv“和时间在顶部,那里很好。这个问题似乎与csv.each
实际上在做任何事情。Ruby CSV枚举混淆
它返回
=> [] 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,名字,姓氏,EMAIL_ADDRESS,HOMEPHONE,街道,城市,州,邮政编码
1,11/12月8日 10:47,艾里,阮,arannon @ jumpstartlab.com,6154385000,3155 19圣 NW,华盛顿,DC,20010
2,11/12月8日 13:23,萨拉,汉金斯,pinalevitsky @ jumpstartlab.com,414-520-5000,2022 15th Street NW,Washington ,DC,20009
3,11/12月8日13:30,萨拉,XX,lqrm4462 @ jumpstartlab.com,(941)979-2000,4175 三街北,圣彼得堡,佛罗里达州,33703
你需要证明你正在阅读的CSV数据的样本。你的意思是你使用Ruby的CSV gem?如果是这样,请显示使用它的代码。 – 2013-04-18 05:11:26
https://github.com/JumpstartLab/curriculum/blob/master/source/projects/event_attendees.csv – user2251284 2013-04-18 05:13:31
不,将最少量的样本数据嵌入到您的问题中,这样我们就不必追究它。当链路断开时,它会使你的问题难以理解。 – 2013-04-18 05:14:52