我正在尝试根据以下条件过滤数据框,如果end_date
是Nan
或如果end_date
大于当前日期。我到底该怎么做?我正在使用以下代码,我知道| and &
运算符是序列运算符。
end_series = ((~df.end_date.notna()) | (df.end_date > datetime.datetime.utcnow().date()))
new_df = df[(df.column1 > 0) & end_series].copy()
你可以做:
current_date = pd.to_datetime("today").date()
new_df = df.query("end_date.isna() or (end_date > @current_date) and column1 > 0")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句