So i built some dataframe using pandas, and eventually i have to export a .csv file with it.
The code looks like this:
df.to_csv('file_name.csv')
and it completely works. However, i need to place the day's date in front of the file_name for easy access and bookkeeping (this process is gonna be repeated many times). So i wrote something like this
today = '30/06/2021'
df.to_csv( today + 'file_name.csv')
but then it doesn't work, it raises: "FileNotFoundError: [Errno 2] No such file or directory: '30/06/2021 file_name.csv'". I also tried many alternatives such as declaring
file_name = '30/06/2021 file_name.csv'
df.to_csv(file_name)
fstrings, string.format() but none worked.
How can I use a variable string to complement file names in pandas?
The full error reads:
File "/home/vni/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py", line 3403, in to_csv
storage_options=storage_options,
File "/home/vni/anaconda3/lib/python3.7/site-packages/pandas/io/formats/format.py", line 1083, in to_csv
csv_formatter.save()
File "/home/vni/anaconda3/lib/python3.7/site-packages/pandas/io/formats/csvs.py", line 234, in save
storage_options=self.storage_options,
File "/home/vni/anaconda3/lib/python3.7/site-packages/pandas/io/common.py", line 652, in get_handle
newline="",
FileNotFoundError: [Errno 2] No such file or directory: '28/06/2021 entregas_saida.csv'
Process finished with exit code 1