我有一个数据帧,它有两列。它有一个名为“DateAndTime”的列(datetime64[ns]) 以及一个名为“Finished”(Bool)的专栏。大约有5000多行,都有不同的日期和时间,并且“Finished”列为True
我想做的是将数据分组为早上7点到晚上7点和晚上7点到早上7点的“班次”,并计算12小时内发生的真实次数
df.head()
DateAndTime Finished
109 2020-07-28 14:36:07.983 True
110 2020-07-28 14:36:34.547 True
111 2020-07-28 14:39:38.187 True
112 2020-07-28 14:41:10.547 True
113 2020-07-28 14:41:32.250 True
df.describe()
DateAndTime Finished
count 5915 5915
unique 5915 2
top 2020-07-29 07:34:25.360000 True
freq 1 5914
first 2020-07-28 14:36:07.983000 NaN
last 2020-08-05 04:57:10.657000 NaN
你应该试试这个
假设您的
DateAndTime
列已经是Timestamp
类型:相关问题 更多 >
编程相关推荐