【发布时间】:2019-10-27 22:24:54
【问题描述】:
我有一个 sql 文件,其中包含我读入 pandas 的数据。
df = pandas.read_sql('Database count details', con=engine,
index_col='id', parse_dates='newest_available_date')
输出
id code newest_date_available
9793708 3514 2015-12-24
9792282 2399 2015-12-25
9797602 7452 2015-12-25
9804367 9736 2016-01-20
9804438 9870 2016-01-20
下一行代码是获取上周的日期
date_before = datetime.date.today() - datetime.timedelta(days=7) # Which is 2016-01-20
我要做的是,将date_before 与df 进行比较,并打印出所有小于date_before 的行
if (df['newest_available_date'] < date_before):
print(#all rows)
显然这会给我一个错误The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
我应该怎么做?
【问题讨论】:
-
还要确保您的列是日期时间类型。使用 df.dtypes