如何将我的代码转换成一行?

How can I convert my code into a single line?

我有以下代码,我想使用列表推导将其转换成一行?但是我一直没有转换成功。

exp_days = ["16/04/2021","23/04/2021","27/04/2021"]

for i in range(len(df)):
    if df["Date"][i] in exp_days:
        list_of_days.append(1)
    else:
        list_of_days.append(0)

我的数据框:

Date
16/04/2021
19/04/2021
20/04/2021
21/04/2021
22/04/2021
23/04/2021
26/04/2021
27/04/2021

预期输出:

list_of_days = [1,0,0,0,0,1,0,1]
list_of_days = [ 1 if df["Date"][i] in exp_days else 0 for i in range(len(df)) ]

通过 numpy 的替代方案 -

exp_days = ["16/04/2021","23/04/2021","27/04/2021"]
import numpy as np
result = np.where(df['Date'].isin(exp_days),1,0)