如果当前数据 e介于 ShiftScheduledStart 和 ShiftScheduledEnd 值之间,我想从数据框df1中删除行。我的想法是下面的代码,但这并没有给出正确的结果。
df1[(df1['ShiftScheduledEnd'] < CurrentDateVar) & (CurrentDateVar < df1['ShiftScheduledStart'])]
有什么问题?
谢谢!
答案 0 :(得分:0)
我不知道你期待什么,但你的行没有满足你的条件:
In [7]:
t="""ShiftScheduledEnd,ShiftScheduledStart
16-5-2015 14:30,16-5-2015 6:00
13-7-2015 22:00,13-7-2015 14:00
13-7-2015 22:30,13-7-2015 14:00
13-7-2015 22:00,13-7-2015 14:00"""
df1 = pd.read_csv(io.StringIO(t), parse_dates=[0,1])
print(df1)
CurrentDateVar = pd.to_datetime('14-7-2015 23:45')
CurrentDateVar
ShiftScheduledEnd ShiftScheduledStart
0 2015-05-16 14:30:00 2015-05-16 06:00:00
1 2015-07-13 22:00:00 2015-07-13 14:00:00
2 2015-07-13 22:30:00 2015-07-13 14:00:00
3 2015-07-13 22:00:00 2015-07-13 14:00:00
Out[7]:
Timestamp('2015-07-14 23:45:00')
In [8]:
df1[(df1['ShiftScheduledStart'] < CurrentDateVar) & (df1['ShiftScheduledEnd'] > CurrentDateVar)]
Out[8]:
Empty DataFrame
Columns: [ShiftScheduledEnd, ShiftScheduledStart]
Index: []