如何计算和记录具有特定月/年值的工作表中的行数(How can I count and log the number of rows in a sheet with a specific month/year value)
我已下载了一个数据集,其中详细列出了1979年1月至2004年12月期间在英格兰报告的所有车祸 - 该文件采用csv格式,可以理解为相当大(确切地说是6,224,199行)。 由于文件的大小超过了Excel 2010可以处理的行数,因此我必须将文件拆分为较小的文件,以便在Excel中一次打开它。 我尝试使用Notepad和Notepad ++,但记事本崩溃,而Notepad ++拒绝打开如此大的(720MB)文件。 我考虑使用像Delimit这样的Excel 替代品 ,但它不支持宏。 现在,忽略大小问题,我需要计算每个月的崩溃总数并记下它们。 有一列用于指定每次崩溃的日期,但不会根据崩溃日期对行进行排序。 我正在考虑使用CTRL + F计算具有特定月/年值的行数,然后记录每次搜索的结果数,但考虑到数据跨越25年,我必须手动搜索并记录300个月的结果。
I've downloaded a dataset which details all of the car accidents reported in England between January 1979 and December 2004 - this file is in csv format and is understandably quite large (6,224,199 rows, to be exact). Because the size of the file exceeds the number of rows that Excel 2010 can handle, I'd have to split the file into smaller ones in order to open it all at once in Excel. I tried using Notepad and Notepad++, but Notepad crashed, and Notepad++ refused to open such a large (720MB) file. I've considered using an Excel replacement like Delimit, but it doesn't support Macros. Now, overlooking the size issue, I need to count the total number of crashes from each month and make a note of them. There's a column to specify the date of each crash, but the rows aren't sorted according to the crash date. I was considering using CTRL+F to count the number of rows with a specific month/year value and then logging the number of results for each search, but considering that the data spans 25 years, I'd have to manually search and record the results from 300 months.
原文:https://stackoverflow.com/questions/28419493
最满意答案
您可以使用
sprintf
将前导0添加到小于4位的小时:strptime(sprintf("%04d", hour), "%H%M")
然后,您可以将其转换为日期:
as.POSIXct(paste(year,day,sprintf("%04d", hour),sep="-"),format = '%Y-%j-%H%M')
You can use
sprintf
to add leading 0s to hours that have less than 4 digits:strptime(sprintf("%04d", hour), "%H%M")
You can then convert it to a date:
as.POSIXct(paste(year,day,sprintf("%04d", hour),sep="-"),format = '%Y-%j-%H%M')
相关问答
更多-
如何在POSIX中提取小时,分钟和秒(忽略日期)(How to extract the hour, minute and seconds in a POSIX (ignoring the date))[2023-09-04]
这是使用data.table执行此操作的一种方法: library(data.table) #I named your dput(head(df[,"Saida"])) as vec time <- as.ITime(vec) time #[1] "06:05:00" "06:23:00" "06:09:00" "05:58:00" "07:32:00" "05:57:00" str(time) #Class 'ITime' int [1:6] 21900 22980 22140 21480 27120 ... -
你可以使用datepart() : select (case when datepart(hour, EndTime) = datepart(hour, getdate()) and datepart(minute, EndTime) = datepart(minute, getdate()) then 1 else 0 end) as status 如果这是你真正想要的,你也可以把它放到更新中。 编辑:更新将是: update ...
-
如果您不需要四分之一小时或作为替代方案(有一些工作)(并且Chris可能已经很久以前就已经发现了这一点),您可以尝试这里详述的答案。 要点是您可以按个别时间元素group(hour(date_time_field) - 例如group(hour(date_time_field)或日期格式: CheckIn.group("date_format(created_at, '%Y%m%d %H/%M')").count 如果你想在四分之一小时内添加,你可以尝试这个 ,然后添加格式 The solution I ...
-
您可以使用sprintf将前导0添加到小于4位的小时: strptime(sprintf("%04d", hour), "%H%M") 然后,您可以将其转换为日期: as.POSIXct(paste(year,day,sprintf("%04d", hour),sep="-"),format = '%Y-%j-%H%M') You can use sprintf to add leading 0s to hours that have less than 4 digits: strptime(sprin ...
-
对于特定的规则,ElastAlert每小时警报而不是分钟警报(ElastAlert alert every hour instead of minute for a certain rule)[2022-08-01]
你可以将realert配置选项设置为60分钟吗? (默认值是1) Realert realert realert:此选项允许您在一段时间内忽略重复的警报。 如果规则使用query_key,则此选项将应用于每个密钥。 对于给定规则的所有匹配,或者对于具有相同query_key的匹配,在给定时间内将被忽略。 所有缺少query_key的匹配将使用_missing的值分组在一起。 这适用于发送警报的时间,而不是事件的发生时间。 它默认为一分钟,这意味着如果ElastAlert在很长的时间段内运行,触发很多匹配,默 ... -
诸如avg()类的聚合函数必须返回interval的一般形式,因为多个值的平均值可以介于两者之间。 这在将来的版本中肯定不会改变。 此外,数据类型在内部是相同的。 只有最不重要的部分会被截断。 行为与其他数据类型类似。 如果计算integer列的平均值,则会得到类型为numeric的结果,该结果可以保存精确的结果。 如果您希望截断结果(而不是您的请求),您可以始终明确地转换为interval hour to minute以确保。 SELECT avg(i)::interval hour to minute ...
-
完整解决方案: String input = "STATUS | webapp | 2014/05/26 15:03:13 | Starting the service..."; String[] splitted = input.split("\\s\\|\\s"); String dateTime = splitted[2]; Calendar c = Calendar.getInstance(); try { Date d = new Simpl ...
-
你需要为此使用groupby ,并且分组应该基于日期和小时: test['DATE'] = test['TIME'].dt.date test['HOUR'] = test['TIME'].dt.hour grp = test.groupby(['DATE', 'HOUR']) 然后您可以遍历这些组并进行所需的操作。 例: for key, df in grp: print(key, df) ((datetime.date(2016, 9, 30), 0), T ...
-
数据仅使用小时分钟(Data use only hour minute seconte)[2022-06-12]
Calendar c = Calendar.getInstance(); int hour = c.get(Calendar.HOUR); 尝试这个。 您可以在Calendar类中使用很多常量。 Calendar c = Calendar.getInstance(); int hour = c.get(Calendar.HOUR); Try this. There are a lot of constants you can use with Calendar class. -
从r [duplicate]中的字符列中提取小时和分钟(extracting hour and minute from character column in r [duplicate])[2022-06-14]
我们可以使用lubridate的方便函数将character列转换为DateTime ,并使用format提取小时和分钟 library(lubridate) v1 <- ymd_hms("2016-05-28T05:53:31.042Z") format(v1, "%H:%M") #[1] "05:53" 或仅使用base R format(as.POSIXct("2016-05-28T05:53:31.042z", format = "%Y-%m-%dT%H:%M:%S"), "%H:%M") #[ ...