как отбрасывать строки по условию - PullRequest
0 голосов
/ 13 февраля 2019

как удалить будильники до 02.06.2009 14:38 и после 02.06.2009 14: 41

Alarm Number    Alarm Type  Severity    Alarm Time  Probable Cause
111 Processing  Minor   06/02/2019 14:25    Application Subsystem Failure
222 Communication   Minor   06/02/2019 14:25    Communication Subsystem Failure
333 Communication   Minor   06/02/2019 14:38    Communication Subsystem Failure
444 Communication   Minor   06/02/2019 14:38    Communication Subsystem Failure
1223    Processing  Minor   06/02/2019 14:38    Application Subsystem Failure
4343    Processing  Minor   06/02/2019 14:39    Application Subsystem Failure
414134  Communication   Minor   06/02/2019 14:39    Communication Subsystem Failure
443314  Communication   Minor   06/02/2019 14:39    Communication Subsystem Failure
1343443 Communication   Minor   06/02/2019 14:39    Communication Subsystem Failure
41343434    Processing  Minor   06/02/2019 14:41    Application Subsystem Failure
343 Communication   Minor   06/02/2019 14:41    Communication Subsystem Failure
343 Communication   Minor   06/02/2019 14:41    Communication Subsystem Failure
34343   Communication   Minor   06/02/2019 14:41    Communication Subsystem Failure
34343   Processing  Minor   06/02/2019 16:44    Application Subsystem Failure
34344   Quality Of Service  Major   12/02/2019 09:48    Database inconsistency

1 Ответ

0 голосов
/ 13 февраля 2019

Используйте to_datetime с dayfirst=True, если формат DD/MM/YYYY HH:MM и тиен фильтр с between с boolean indexing:

df['Alarm Time'] = pd.to_datetime(df['Alarm Time'], dayfirst=True)

#change format dates
df = df[df['Alarm Time'].between('2019-02-06 14:38:00','2019-02-06 14:41:00')]
print (df)
    Alarm Number     Alarm Type Severity          Alarm Time  \
2            333  Communication    Minor 2019-02-06 14:38:00   
3            444  Communication    Minor 2019-02-06 14:38:00   
4           1223     Processing    Minor 2019-02-06 14:38:00   
5           4343     Processing    Minor 2019-02-06 14:39:00   
6         414134  Communication    Minor 2019-02-06 14:39:00   
7         443314  Communication    Minor 2019-02-06 14:39:00   
8        1343443  Communication    Minor 2019-02-06 14:39:00   
9       41343434     Processing    Minor 2019-02-06 14:41:00   
10           343  Communication    Minor 2019-02-06 14:41:00   
11           343  Communication    Minor 2019-02-06 14:41:00   
12         34343  Communication    Minor 2019-02-06 14:41:00   

                     Probable Cause  
2   Communication Subsystem Failure  
3   Communication Subsystem Failure  
4     Application Subsystem Failure  
5     Application Subsystem Failure  
6   Communication Subsystem Failure  
7   Communication Subsystem Failure  
8   Communication Subsystem Failure  
9     Application Subsystem Failure  
10  Communication Subsystem Failure  
11  Communication Subsystem Failure  
12  Communication Subsystem Failure  
...