How to obtain a count of the classes of a categorical var within a certain time interval for a time-stamped data? I have a dataframe with several categorical variables. But for simplicity let's assume there is only 1 categorical variables with 3 classes. I want to obtain the counts of these classes within a certain time-intervals, say 15mins. To make it easier to understand what I am looking for, here is a toy example and the output I am looking for.
                    _time       AN
0 2019-04-09 16:00:00.050        a
1 2019-04-09 16:00:00.050        a
2 2019-04-09 16:00:00.050        b
3 2019-04-09 16:00:00.050        a
4 2019-04-09 16:00:00.050        b
5 2019-04-09 16:02:38.992        a
6 2019-04-09 16:06:41.884        c
7 2019-04-09 16:15:00.051        a
8 2019-04-09 16:15:00.051        b
9 2019-04-09 16:15:00.051        a

The output that I am looking for is below:
_time               AN          
2019-04-09 16:00:00 a                4
                    b                2
                    c                1
2019-04-09 16:15:00 a                2
                    b                1

So for this toy example, the timeline has two 15mins intervals. For the first one, 'a' appears 4 times, 'b' appears 2 times and 'c' appear 1 time. In the 2nd 15min interval, 'a' appears 2 times and 'b' appear only 1 time and 'c' doesn't appear at all.
I obtained this result by running this code:
c.resample('15T',on = '_time').agg({'AN':'value_counts'})

However, when I am running this same code on the entire dataframe, df, I am getting the following error:
ValueError: operands could not be broadcast together with shape (10267,) (4315,)
I am not sure why I am getting this. Is there a different method to obtain the same result? or is there any suggestion to fix this error?
Thanks in advance.
import pandas as pd
data = pd.read_csv(&quot;/content/da_time.txt&quot;,header=None) # File has your example data
data.columns=['num','date_time','var']     # Named columns
data.date_time = pd.to_datetime(data.date_time) # To Pandas datetime
data['date_time_copy'] = data.date_time   # Created a copy of datetme column

# make second as multiple of 15 and millisecs=0
data['date_time_copy'] = data.date_time_copy.apply(lambda x:x.replace(minute=x.minute//15*15,second=0,microsecond=0))

data.groupby(by=['date_time_copy','var']).count()['num']

Output