我希望有人可以帮助我解决这个问题,
我有一个 df,其中一列是时间序列。
我需要根据时间将这些时间序列分组为 4 个不同的值。我想将时间按 07:00 - 11:30、11:31 - 16:59、17:00 - 19:59 和最后 20:00 - 24:00 分组。每个组可以命名为 1、2、3 和 4。
最后将该列添加到我的 df.
最好的问候和感谢!
编辑添加一个可重现的例子:
c( "07:02:03", "07:32:03", "08:02:03", "08:32:03",
"09:02:03", "09:32:03", "10:02:03", "10:32:03", "11:02:03", "11:32:03",
"12:02:03", "12:32:03", "13:02:03", "13:32:03", "14:02:03", "14:32:03",
"15:02:03", "15:32:03", "16:02:03", "16:32:03", "17:02:03", "17:32:03",
"18:02:03", "18:32:03", "19:02:03", "19:32:03", "20:02:03", "20:32:03",
"21:02:03", "21:32:03", "22:02:03", "22:32:03", "23:02:03", "23:32:03",
"00:02:03", "00:32:03", "01:02:03", "01:32:03", "02:02:03", "02:32:03",
"03:02:03", "03:32:03", "04:02:03", "04:32:03", "05:02:03", "05:32:03",
"06:02:03", "06:32:03", "07:02:03", "07:32:03", "08:02:03", "08:32:03",
"09:02:03", "09:32:03", "10:02:03", "10:32:03", "11:02:03", "11:32:03",
"12:02:03", "12:32:03", "13:02:03", "13:32:03", "14:02:03", "14:32:03",
"15:02:03", "15:32:03", "16:02:03", "16:32:03", "17:02:03", "17:32:03",
"18:02:03", "18:32:03", "19:02:03", "19:32:03", "20:02:03", "20:32:03",
"21:02:03", "21:32:03", "22:02:03", "22:32:03", "23:02:03", "23:32:03",
"00:02:03", "00:32:03", "01:02:03", "01:32:03", "02:02:03", "02:32:03",
"03:02:03", "03:32:03", "04:02:03", "04:32:03", "05:02:03", "05:32:03",
"06:02:03", "06:32:03", "07:02:03", "07:32:03", "08:02:03", "08:32:03",
"09:02:03", "09:32:03", "10:02:03", "10:32:03", "11:02:03", "11:32:03",
"12:02:03", "12:32:03", "13:02:03", "13:32:03", "14:02:03", "14:32:03",
"15:02:03", "15:32:03", "16:02:03", "16:32:03", "17:02:03", "17:32:03",
"18:02:03", "18:32:03", "19:02:03", "19:32:03", "20:02:03", "20:32:03",
"21:02:03", "21:32:03", "22:02:03", "22:32:03", "23:02:03", "23:32:03",
"00:02:03", "00:32:03", "01:02:03", "01:32:03", "02:02:03", "02:32:03",
"03:02:03", "03:32:03", "04:02:03", "04:32:03", "05:02:03", "05:32:03",
"06:02:03", "06:32:03", "07:02:03", "07:32:03", "08:02:03", "08:32:03",
"09:02:03", "09:32:03", "10:02:03", "10:32:03", "11:02:03", "11:32:03",
"12:02:03", "12:32:03", "13:02:03", "13:32:03", "14:02:03", "14:32:03",
"15:02:03", "15:32:03", "16:02:03", "16:32:03", "17:02:03", "17:32:03",
"18:02:03", "18:32:03", "19:02:03", "19:32:03", "20:02:03", "20:32:03",
"21:02:03", "21:32:03", "22:02:03", "22:32:03", "23:02:03", "23:32:03",
"00:02:03")
-Hlynur
EDIT2:添加样本df,
a b c
1 3 09:00
2 5 13:00
3 8 16:00
4 7 21:00
5 9 19:00
6 2 22:00
......
然后 d 列会给我组 (1,2,2,4,3,4)