I have this simple code which saves a pandas dataframe to a csv file. As of now, it works by overwriting the filename so each time I run it it just replaces the old file with a new one with the same name. Is it possible to save this dataframe but have it create new files sequentially, ie if there is already some file called "filename1" in the directory make the new one called "filename2" so the data from the original file is not just lost?
import pandas
datamatrix= [[1,2,3],[1,2,3],[1,2,3]])
x=pandas.DataFrame(datamatrix)
pandas.DataFrame.to_csv(x,"filename.csv",',')
os.path.exists(filename), but enumerating it into infinity may not really what you want, it may be a better idea to add a timestamp in one way or another to it that conflicts only once. Something likefilename_201806150311.csv