我正在尝试使用pd.cut来记录行,详细说明在不同时间长度内进行测试的结果 . 这些箱的目的是最终添加一个新列,我可以根据该测试结果记录的时间戳是否落在该测试的定义时间范围内来定义每行测试结果所属的测试 .
df中的数据如下所示
Index DeviceID QuantResult1 QuantResult2 Timestamp
0 15D 7903 387403 2017-10-14 00:28:00
1 15D 3429734 786 2017-10-14 00:29:10
2 15D 2320923 546 2017-10-14 00:31:15
3 15D 232 435869 2017-10-14 00:50:05
4 15D 34032984 12 2017-10-14 01:10:07
到目前为止,我尝试为每个单独的测试创建单独的日期时间范围
test_1 = pd.date_range(start = '2017-10-14 00:20:00', end = '2017-10-14 00:33:15', freq = 'S')
test_2 = pd.date(pd.date_range(start = '2017-10-14 00:49:15', end = '2017-10-14 01:15:15', freq = 'S')
等等
然后我在所有测试中创建了一个date_ranges列表
test_list = [test_1,test_2]
然后我尝试使用pd.cut
df = pd.cut(df['Timestamp'],bins = test_list, labels = ['Test_1','Test_2'])
但是我收到以下错误:
TypeError: type object 0.
最终我希望数据看起来像这样
Index DeviceID QuantResult1 QuantResult2 Timestamp Test
0 15D 7903 387403 2017-10-14 00:28:00 Test_1
1 15D 3429734 786 2017-10-14 00:29:10 Test_1
2 15D 2320923 546 2017-10-14 00:31:15 Test_1
3 15D 232 435869 2017-10-14 00:50:05 Test_2
4 15D 34032984 12 2017-10-14 01:10:07 Test_2
你能告诉我错误的来源是什么吗?
我已经尝试将test_list映射为整数,并在将df ['Timestamp']列转换为np.int64之后与df进行比较,如下所示 .
test_list_int64 = list(map(np.int64,test_list))
df = pd.cut(df['Timestamp'].astype(np.int64),bins = test_list_int64)
但是这种努力给出了以下错误:
ValueError: operands could not be broadcast together with shapes (1320,) (87480,)
谢谢!