When we are checking a DataFrame object is valid or not, ValueError: The truth value of a DataFrame is ambiguous will be reported. In this tutorial, we will introduce how to fix this error.
Look at example code below:
df_source = None if os.path.exists(excel_name): df_source = pd.DataFrame(pd.read_excel(excel_name, sheet_name=sheet_name)) print(df_source) if df_source: df_dest = df_source.append(df) print(df_dest)
If df_source is valid, we will output it.
Run this code, we will get this result:
How to fix this value error?
We can use code below to fix.
if df_source is not None: df_dest = df_source.append(df) print(df_dest)