我正在尝试过滤Dataframe,但当我运行以下代码时,它返回空的dataframe:
allot_df = allot_df[(allot_df['dispatch_date'].dt.month == 1) &
(allot_df['dispatch_date'].dt.year == 2021 ) &
(allot_df['Increased Cycle Time'] > 0) &
(allot_df['kit']==row.kit)]但是,当我通过excel应用相同的筛选器时,它工作得很好,我无法识别代码中的问题。
因此,我使用固定的值运行它,但仍然存在相同的错误
原始代码应该是:
allot_df = allot_df[(allot_df['dispatch_date'].dt.month == int(row.delivery_month[:2])) &
(allot_df['dispatch_date'].dt.year == int(row.delivery_month[-4:])) &
(allot_df['Increased Cycle Time'] > 0)&
(allot_df['kit']==row.kit)]我尝试打印变量的值以纠正不匹配,但它们是相同的
print("month df", row.delivery_month[:2])
print("month df", row.kit)
print("month df", type(row.delivery_month[:2]))
month df 02
month df KIT1216A
month df <class 'str'>发布于 2021-02-09 17:36:58
我想您忘了在查询中添加.iloc。如下所示:
allot_df = allot_df.iloc[(allot_df['dispatch_date'].dt.month == 1) &
(allot_df['dispatch_date'].dt.year == 2021 ) &
(allot_df['Increased Cycle Time'] > 0) &
(allot_df['kit']==row.kit)]https://stackoverflow.com/questions/66115994
复制相似问题