I am trying to run a cell in Jupyter notebook and getting permission error number 13. The code is
df_manual_testing = pd.concat([df_fake_manual_testing,df_true_manual_testing], axis = 0)
df_manual_testing.to_csv("manual_testing.csv")
The error which I am getting is:
---------------------------------------------------------------------------
PermissionError Traceback (most recent call last)
<ipython-input-16-f14a4d175882> in <module>
1 df_manual_testing = pd.concat([df_fake_manual_testing,df_true_manual_testing], axis = 0)
----> 2 df_manual_testing.to_csv("manual_testing.csv")
~\anaconda\lib\site-packages\pandas\core\generic.py in to_csv(self, path_or_buf, sep, na_rep, float_format, columns, header, index, index_label, mode, encoding, compression, quoting, quotechar, line_terminator, chunksize, date_format, doublequote, escapechar, decimal)
3202 decimal=decimal,
3203 )
-> 3204 formatter.save()
3205
3206 if path_or_buf is None:
~\anaconda\lib\site-packages\pandas\io\formats\csvs.py in save(self)
182 close = False
183 else:
--> 184 f, handles = get_handle(
185 self.path_or_buf,
186 self.mode,
~\anaconda\lib\site-packages\pandas\io\common.py in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text)
426 if encoding:
427 # Encoding
--> 428 f = open(path_or_buf, mode, encoding=encoding, newline="")
429 elif is_text:
430 # No explicit encoding
PermissionError: [Errno 13] Permission denied: 'manual_testing.csv'
I cannot understand how to change the permission of my file. I think so I will need to change it from root to user, but I am not sure exactly how to do this.
CodePudding user response:
If you are not interested in writing the csv file into the current working directory, you could simply specify the full path of a folder in which you are sure you have the permissions to write.
For example:
df_manual_testing.to_csv("C:/Users/../manual_testing.csv")
However, if you want to write in a particular folder, you can check from the terminal if you have the permissions to write here, using the command ls -lh
. Eventually, you could change the permissions using the account of the owner of the folder, with the command chmod 777 myfolder
.
If you need more information about file permissions, you could look at this reference.