I have a python code (running on terminal) where I am converting a Dataframe to a .csv file by the following code:
#Converting the dataframe to a csv file
relative_path = os.path.dirname(__file__)
df.to_csv(relative_path+"/"+args.cleaned, index=False)
where args.cleaned
is defined in the upper portion of the code as follows:
import argparse
parser = argparse.ArgumentParser(description="Run data cleaning.")
parser.add_argument('--cleaned', type=str, default='final.csv', help='Cleaned csv output')
While doing this I’m getting the following error:
OSError: [Errno 30] Read-only file system: '/final.csv'
I’ve searched this error on Google and stackOverflow and tried several things like giving read/write permission to the working directory using chmod. The most relevant source I got was this stackOverflow link. But it concerns a directory and many solutions do not apply to a file like I’m using a .csv file.
This code ran successfully before for many months in the same working directory of the same device, and I never had a problem regarding this. Recently I had to reinstall Anaconda and Python, and just after that, I’m having this issue. I have gone through almost all StackOverflow posts related to this error but didn’t find the solution, specifically for a .csv file in Python.
Any suggestion would be highly appreciated.