У меня есть следующий фрейм данных:
df = pd.DataFrame({'Depth' : [13000, 13012, 13015, 13020, 13055, 17000,
18000, 19000, 20000, 33000, 33050, 33300,
33400, 24542, 30000, 30009, 30000, 30050,
30051, 20000, 18000, 9000],
'Date': ['2019-10-10 01:14:14', '2019-10-10 03:14:14',
'2019-10-10 06:14:14', '2019-10-10 09:14:14',
'2019-10-10 14:14:14', '2019-10-10 14:14:14',
'2019-10-10 14:14:14', '2019-10-10 14:14:14',
'2019-10-10 14:14:14', '2019-10-10 14:14:14',
'2019-10-10 14:15:14', '2019-10-10 14:16:14',
'2019-10-10 14:17:14', '2019-10-10 14:18:14',
'2019-10-10 14:19:14', '2019-10-10 14:20:14',
'2019-10-10 14:21:14', '2019-10-10 14:22:14',
'2019-10-10 14:23:14', '2019-10-10 14:24:14',
'2019-10-10 14:25:14', '2019-10-10 14:26:14']
})
Мне нужно было добавить новый столбец в фрейм данных.
Требуемый вывод:
Depth Date Classification
13000 2019-10-10 01:14:14 nan #not accepted because the readings are too far in time
13012 2019-10-10 03:14:14 nan #not accepted because the readings are too far in time
13015 2019-10-10 06:14:14 nan #not accepted because the readings are too far in time
13020 2019-10-10 09:14:14 nan #not accepted because the readings are too far in time
13055 2019-10-10 14:14:14 nan #not accepted because the readings are too far in time
17000 2019-10-10 14:14:14 nan #not accepted because the depth values are far
18000 2019-10-10 14:14:14 nan #not accepted because the depth values are far
19000 2019-10-10 14:14:14 nan #not accepted because the depth values are far
20000 2019-10-10 14:14:14 nan #not accepted because the depth values are far
33000 2019-10-10 14:14:14 Accept
33050 2019-10-10 14:15:14 Accept
33300 2019-10-10 14:16:14 Accept
33400 2019-10-10 14:17:14 Accept
24542 2019-10-10 14:18:14 nan
30000 2019-10-10 14:19:14 Accept
30009 2019-10-10 14:20:14 Accept
30000 2019-10-10 14:21:14 Accept
30050 2019-10-10 14:22:14 Accept
30051 2019-10-10 14:23:14 Accept
20000 2019-10-10 14:24:14 nan
18000 2019-10-10 14:25:14 nan
9000 2019-10-10 14:26:14 nan
Примечание : показания датчика глубины принимаются, когда разница глубин меньше 1500, а дата показаний близка (разница приблизительно в 10 минут).
Я попытался реализовать следующий код (этот код неверен):
df['var_time'] = df['Date'].diff()
df['var_delta_sensor'] = df['depth'].diff().abs()
time_delta=datetime.timedelta(minutes=10) #10 minutes
df['Classification'] = np.where((( df['var_time'] < time_delta) &
(df['var_delta_sensor'] <1500)), 'Accept', np.NaN)
Мой неверный вывод:
depth Date var_time var_delta_sensor Classification
13000 2019-10-10 01:14:14 NaT NaN nan
13012 2019-10-10 03:14:14 02:00:00 12.0 nan
13015 2019-10-10 06:14:14 03:00:00 3.0 nan
13020 2019-10-10 09:14:14 03:00:00 5.0 nan
13055 2019-10-10 14:14:14 05:00:00 35.0 nan
17000 2019-10-10 14:14:14 00:00:00 3945.0 nan
18000 2019-10-10 14:14:14 00:00:00 1000.0 Accept
19000 2019-10-10 14:14:14 00:00:00 1000.0 Accept
20000 2019-10-10 14:14:14 00:00:00 1000.0 Accept
33000 2019-10-10 14:14:14 00:00:00 13000.0 nan
33050 2019-10-10 14:15:14 00:01:00 50.0 Accept
33300 2019-10-10 14:16:14 00:01:00 250.0 Accept
33400 2019-10-10 14:17:14 00:01:00 100.0 Accept
24542 2019-10-10 14:18:14 00:01:00 8858.0 nan
30000 2019-10-10 14:19:14 00:01:00 5458.0 nan
30009 2019-10-10 14:20:14 00:01:00 9.0 Accept
30000 2019-10-10 14:21:14 00:01:00 9.0 Accept
30050 2019-10-10 14:22:14 00:01:00 50.0 Accept
30051 2019-10-10 14:23:14 00:01:00 1.0 Accept
20000 2019-10-10 14:24:14 00:01:00 10051.0 nan
18000 2019-10-10 14:25:14 00:01:00 2000.0 nan
9000 2019-10-10 14:26:14 00:01:00 9000.0 nan