I am working on a project in which I want to load a dataframe using the csv file and check if the file from which I want to load the dataframe is empty or not. If the csv file is empty then as soon as the statement df=pd.read_csv(file.csv) is encountered , I get the error pandas.errors.EmptyDataError: No columns to parse from file Please help me
#custom error class defined correctly
try:
#file.csv is an empty csv file
df=pd.read_csv(file.csv)
if df:
print("Dataframe loaded successfully!!")
else:
raise Empty_csv_file_Error("The csv file is empty!!")
except Empty_csv_file_Error as e:
print(e.msg)
Error encountered while loading the dataframe using empty csv file :- pandas.errors.EmptyDataError: No columns to parse from file