What is the easiest way to delete an entire Excel sheet (CSV comma delimited)? Overwriting the sheet to be blank could also work.
I need this to be automated. It should delete the sheet at the end of this loop.
My code so far:
file_name =r'C:\Users\Trading\Desktop\scott\test.csv'
while True:
df=pd.read_csv(file_name, header=None, encoding="latin1")
if file_name is not "":
df=pd.read_csv(file_name, header=None)
lastRow = df.iloc[-1]
stock=(lastRow[0])
price=(lastRow[3])
print (stock, action, num_shares, price)
os.remove(file_name)
#csv_file.unlink() #I also tried this way..
print("file deleted")
UPDATE ERROR MESSAGE
Now I am getting the error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 18: invalid start byte.