Nic*_*las 1 python pandas python-typing
我有一个这样定义的函数:
def demand_cleaning(df=None, location, output,_input,tables):
Run Code Online (Sandbox Code Playgroud)
我想测试是否df通过(df是熊猫DataFrame)
如果df没有通过,我想做类似的事情
if df is None:
df = pd.read_pickle(tables + "Demand Raw")
Run Code Online (Sandbox Code Playgroud)
但是这个测试现在不起作用。我明白了
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Run Code Online (Sandbox Code Playgroud)
你可以说:
if df is None:
Run Code Online (Sandbox Code Playgroud)
如果要检查数据框是否包含数据检查:
if not df.empty:
Run Code Online (Sandbox Code Playgroud)