Is there a way of using to_csv("xxx.csv")
in Python without overwriting an existing file?
In other words, if I ran to_csv("xxx.csv")
twice in succession, I would like to have 2 output files in my folder, not one.
Is there a way of using to_csv("xxx.csv")
in Python without overwriting an existing file?
In other words, if I ran to_csv("xxx.csv")
twice in succession, I would like to have 2 output files in my folder, not one.
In order to have two different files, you need to give them two different names. There is no way around this, and it makes sense and is usually enforced at the OS level.
You can try it yourself by trying to create two files with the same name via the terminal or a GUI.
Answering my own question for the benefit of other users. I am running a monthly process and so the only way to not overwrite files is to use .format()
within the file name.
e.g. .to_csv("xxx{}.csv".format(a), index=False)
, where a
increases by 1 each month, so there is no overwriting involved.