Yesterday I imported an sas file into Pandas, and was able to successfully poke around the data. This morning, I received a file not found error, although I did not move any files.
I triple-checked the path and it was correct. Then I tried placing a copy of the file on my desktop and redirecting read command. Same error. (This is the type of thing that makes you feel crazy.) Any help appreciated.
Unless that you have a folder named Dropbox inside your project directory, I suggest you use the full path of your file:
/home/<username>/Dropbox/Thesis Fall 2017/Data Analysis/epcg17.xpt
OR
~/Dropbox/Thesis Fall 2017/Data Analysis/epcg17.xpt
Both should work.
Related
I have been working on a project but while opening files from different folders I came across this peculiar problem where the relative path for a file within the same directory is not opening with this statement:-
But works perfectly fime with this statement:-
even when I don't mention folder description, like directly using the file name in statement, it shows error:-
Can anyone give a explaination for what is going wrong here?
Also this file is working in this particular location only, i.e. if I move the complete project to another location on the computer or to another computer, all the methods fail and I need to mention absolute path in order to make it work.
I'm working on automating some reporting for work which starts off with a pd.read_excel method. It worked fine and I moved on with the rest of my code. When I was done, I had a few ipynb files on my desktop and moved them into a folder called "Python". After doing so, I'm getting a "No such file or directory" error when rerunning the code. The file is in a folder called "Reporting". I can leave them on the desktop for now, but typically have everything organized in folders to avoid clutter. What do I need to do to get my code to continue read in the excel files?
RawData=pd.read_excel("Reporting/LS_Questions.xlsx",skiprows=2)
Try using an absolute path rather than a relative path.
Right now your path assumes that the file is within the same directory as the notebook.
you can either:
use a full path a.i - "C:\User{user_name}\Desktop\LS_Questions.xlsx"
Move the CSV/XL file to the directory of the notebook.
I installed spyder with pip (not with anaconda).
Whenever I save a .py file, spyder also generates a temp file containing a copy of the file source, in the same directory. Something like this
where each file starting with "tmp" contains the source of a different version of main.py. In the past, when I installed spyder with Anaconda, this never occurred.
Is there a way to deactivate this feature? Or at least to force spyder to save these temp files somewhere else?
Not sure if you are still troubled by this issue. Are you using Dropbox or some similar services?
I've met the same problem as you did, and I found the reason on Github, see #13041.
If you can try to work outside Dropbox, you don't see any tmp files. This works for me and hope it can help you.
I know there must be a really obvious answer, but it eludes me. Where does "/folder1/folder2/file.ext" save to in Python? In some code I thought (incorrectly) that it would save the file to a relative path, but when I checked folder2 it wasn't there. However, it seemed to still take up the hard disk space. I did a search on my hard drive and couldn't find the file. Where did it go? Again, I'm aware that there must be a really obvious answer out there, but I am just learning to code.
Firstly I would read about the os module and the module search path.
I opened the IDLE 3.7.0 on my Windows 10 machine and did the following:
>>> import os
>>> os.getcwd()
'C:\\Python37'
>>> os.path.abspath('./folder1')
'C:\\Python37\\folder1'
Windows expands the . to represent the current working drive, thus wherever the interpreter is looking is where your folders will reside.
In the links, it talks about how sys.path works (in short the directory containing the current script is placed at the front of it [e.g. the current working directory] for searching).
So, in short, either run your script directly from the directory or call os.chdir('/your/desired/path').
I am wanting to package my program that uses over files to store user data locally, but I don't know what directory I should put in all the json.load and json.dump. So right now, I have the directory equal to json.dump(somelist,open('/home/username/filename','w')) but when someone downloads it, the program won't work since it is a different directory. I am trying to PyInstaller but maybe PyInstaller will do it for me. I was just wondering and I couldn't find anything on google but if there is something, please link it to me. Thanks in advance!!
Use the following to get the user's home directory:
from os.path import expanduser
home = expanduser("~")
with open(os.path.join(home, 'file'), 'w') as sr:
json.dump(somelist, sr)