1 回答
TA贡献1789条经验 获得超8个赞
这看起来很简单。您的函数可能如下所示:
def get_holdings_df_date(d):
return True if str(d) in holdings_df["Date"].values else False
整个代码示例:
import pandas as pd
test = [
("2020-01-02", 34, "Sydney", 155),
("2020-01-03", 31, "Delhi", 177),
("2020-01-04", 16, "Mumbai", 81),
("2020-01-05", 31, "Delhi", 167),
("2020-01-06", 81, "Delhi", 144),
("2020-01-07", 35, "Mumbai", 135),
("2020-01-08", 35, "Colombo", 111),
("2020-01-09", 32, "Colombo", 111),
]
holdings_df = pd.DataFrame(test, columns=["Date", "x", "y", "z"])
def get_holdings_df_date(d):
return True if str(d) in holdings_df["Date"].values else False
print(get_holdings_df_date("2020-01-02"))
输出:
True
添加回答
举报