I got a CSV file which sometimes it's empty and sometimes got content in it. I am trying to check if the CSV is empty or not, so I could know if to append to it or recreate it.
I have tried this:
check_df = pd.read_csv(r'my file')
if check_df.empty:
csvfile = open(r'my file', 'w', newline='')
obj = csv.writer(csvfile)
obj.writerow(["date", "bmo amc", "stock symbol","company name"])
print("csv empty")
else:
csvfile = open(r'my file', 'a', newline='')
obj = csv.writer(csvfile)
print("appending csv")
this code gives me the error:
pandas.errors.EmptyDataError: No columns to parse from file
pretty new to python if you can please be clear with the answers thanks.