I've learned from Python - Files I/O
mode='a'
:Opens a file for appending. The file pointer is at the end of the file if the file exists. That is, the file is in the append mode. If the file does not exist, it creates a new file for writing.
So where i can find an explaination about why pd.ExcelWriter(
mode='a)
can not creat file if file doesn't exists?
If pd.ExcelWriter('path+filename', mode='a')
does not creat a new file. Is there any other better way to do so?
The only way i can find is
if os.path.exists(filename):
with pd.ExcelWriter(filename, mode='a') as writer:
"blabla"
else:
with pd.ExcelWriter(filename, mode='w') as writer:
"blabla"