假设我有一个Pandas 数据框,如下所示(有数百万行)-
data = {'s3_path': ['s3://mybucket/date=2023-10-26/f1.txt', 's3://mybucket/date=2023-10-25/f2.txt', 's3://mybucket/date=2023-10-24/f3.txt', 's3://mybucket/date=2023-10-23/f4.txt']}
df = pd.DataFrame(data)
我想过滤2023-10-24
之前的S3路径.在大Pandas 身上做到这一点的有效方法是什么?我对Pandas 了解不多,能想到的如下,但还不完整:
date_cutoff_str = '2023-10-24'
date_cutoff_obj = datetime.strptime(date_cutoff_str, '%Y-%m-%d')
def is_before(cur_date, cutoff_date):
if cur_date < cutoff_date:
True
return False
date_regex_pattern = r'\d{4}-\d{2}-\d{2}'
filtered_df = df.apply(is_before, cur_date=how_do_i_get_regex_value_here, cutoff_date=date_cutoff_obj)
如有任何建议/答复,我们将不胜感激.谢谢.