我有一份按日排序的小时级别的csv数据,涵盖了数百天的数据:
2011.05.16,00:00,1.40893
2011.05.16,01:00,1.40760
2011.05.16,02:00,1.40750
2011.05.16,03:00,1.40649
我想要统计每小时设置了多少次每日最大值,因此如果在00:00我拥有2011.05.16日的最大值,则在00:00时加1,并依此类推。为此,我使用了一个循环来按索引计算小时数:
def graph():
Date, Time, High = np.genfromtxt(myPath, delimiter=",",
unpack = True, converters={0:date_converter})
numList = [""] * 24
index=0
hour=0
count = [0] * 24
for eachHour in Time:
numList[hour] += str(High[index])
index += 1
hour +=1
if hour == 24:
higher = (numList.index(max(numList)))
count[higher] += 1
hour = 0
numList = [""] * 24
问题在于我的数据中经常会出现一些缺失几个小时的间隔,但是循环无法识别它并继续将值放入下一个小时索引中。我已经到处搜索了,但我是编程新手,这是我第一次进行“复杂”的工作,因此我需要更具体的答案来了解它的工作原理。 那么如何像所解释的那样制作每小时频率计数?
最终结果应该是:00:00 n time max of the day
01:00 n time max of the day
02:00 n time max of the day
etc
pandas
添加为标签,但似乎并未使用它。是否接受基于pandas
的解决方案? - DSM