How to obtain a count of the classes of a categorical var within a certain time interval for a time-stamped data?
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