-2
0        2019-04-01 09:31:39      1
1        2019-04-01 09:47:33      1
2        2019-04-01 09:48:17      1
3        2019-04-01 09:57:52      1
4        2019-04-01 10:03:59      1
5        2019-04-01 10:07:10      1
6        2019-04-01 10:28:40      1
7        2019-04-01 10:43:18      1
8        2019-04-01 10:48:52      1
9        2019-04-01 10:51:56      1
10       2019-04-01 10:55:59      1
11       2019-04-01 10:59:20      1
12       2019-04-01 11:12:05      1
13       2019-04-01 12:23:09      1
14       2019-04-01 12:23:13      1
15       2019-04-01 12:25:47      1
16       2019-04-01 12:32:39      1
17       2019-04-01 12:55:32      1
18       2019-04-01 13:06:05      1
19       2019-04-01 13:29:35      1

how to cluster all the 1s in accordance to the time sorted by 1hr frequency ?

please do help !

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
  • What do you exactly mean with "cluster"? What is your expected output – Erfan Aug 24 '19 at 18:54
  • 1
    do you mean `df.set_index('first_column').resample('H').sum()`, `sum/mean`..etc.. – anky Aug 24 '19 at 19:16
  • output should look like 09:31:39 to 10:28:40 = 7 – Karun Aditya Aug 25 '19 at 03:36
  • I finde the question really unclear. By 'cluster all 1s in acordance to the time sorted by 1 hr freq' I understand you want to get how many 1s are per hour? But then your last comment states an example which doesn't reflect what I got. I suggest you to try to improve the question a bit; then it'll be easier to help. – 89f3a1c Aug 27 '19 at 23:07

1 Answers1

0

If what you want is to get how many 1s are per hour, you should do

df['hour'] = df['time'].dt.hour
df.groupby('hour')['other_col'].sum()

where time is the name of the column with the timestamp and other_col the name of the column with the 1s.

Anyway, this is a simpler way of doing what anky stated in the comments, but with a little more begginer-friendly syntax.

Hope this helps!

89f3a1c
  • 1,430
  • 1
  • 14
  • 24