I made a simple code that loads in data called 'original.dat' from a folder named 'data' in my computer. The code was working great and i was able to view my spectra graph. This morning I ran the code again, but it completely crashed giving the error " OSError: data/original.dat not found." Even though nothing changed. The data is infact still in the folder named 'data' and there isn't any spelling mistakes. Can anyone please help understand why its now giving me this error? The code was working perfectly the day before.
here is the code I used :
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
OPUSimaginary = np.loadtxt('data/original.dat', delimiter = ',')
Data file position, Error:cant find the file,Error: suggested code to find file
Few things that you can do to avoid file not found type of issues:
Add a check if the file exists before trying to load it.
Example:
import os
os.path.isfile(fname) # Returns True is file found
Make sure the file permissions are correct and the file can be read.
sudo chmod -R a+rwx <file-name>
Related
I know this particular question has been asked loads of times but I have searched through and tried multiple approaches to solve this all with the same issue still existing so unfortunately have to ask for help because I cannot solve myself.
I have the following package installed: https://github.com/skagr/footballdata
When trying to read_games I get the dreadful error message. After reading through some of the package it looks as though it should overwrite the data if it already exists but I think this is more of a windows error.
Any help will be appreciated.
I have tried creating a parent structure in the folders but the same error exists. Also tried using Pathlib to say if folder exists=OK but still doesnt solve the error.
edit: Code added.
import numpy as np
import pandas as pd
import requests
import unidecode
import footballdata as foo
import pathlib
pathlib.Path('C:\\Users\\username\\.spyder-py3\\data').mkdir(parents=True, exist_ok=True)
EPL = foo.MatchHistory('ENG-Premier League', [22]).read_games()
print(EPL.head())
As you can see there isnt much to it but getting the error stops anything getting past this point.
thanks
I am participating the kaggle's NCAA March Madness Anlytics Competion. I used pandas to read the information from csv files but encountered such a problem:
seeds = pd.read_csv('/kaggle/input/march-madness-analytics-2020/2020DataFiles/2020DataFiles/2020-Womens-Data/WDataFiles_Stage1/WNCAATourneySeeds.csv')
seeds
Here the output is empty. And I tried again like this:
rank = seeds.merge(teams)
Then there came an error:
NameError: name 'seeds' is not defined.
I can't figure out what happened and I tried it offline which turned out that nothing happened. Do I miss anything? And how can I fix it? Note that this was not the first time I used the read_csv() to read data from csv file in this notebook, though I couldn't figure out whether there is relation between this trouble and my situation.
You must put the CSV file in the folder where python saves projects.
Run this to find out the destination:
%pwd
Put the file in the destination and run this:
seeds = pd.read_csv('WNCAATourneySeeds.csv')
You can also run this:
seeds = pd.read_csv(r'C:\Users....\WNCAATourneySeeds.csv')
Where "C" is the disk where your file is saved and replace "..." by the computer path where the file is saved. Use also "\" not "/".
I finally found the problem. I didn't notice I was writing my codes in the markdown cell. Stupid me!
I was trying to read a dataset but I'm getting this weird error:
FileNotFoundError: [Errno 2] File b'Position_Salaries.csv' does not exist: b'Position_Salaries.csv'
Even though the file does exist and its on the same directory of my code (As you can see in this pic)
The weird thing is, I've run that code many times without getting any kind of error, but suddenly (without changing anything)is not working. I literally just opened Spyder, try to run the code, but nope, that error appeared. Any ideas why is this happening and how can I solve it?
Part of the code I'm trying to run:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
dataset = pd.read_csv('Position_Salaries.csv')
X = dataset.iloc[:, 1:2].values
y = dataset.iloc[:, 2].values
There is a tool tip that is obscuring your picture but from the information provided I would guess that your working directory is not set to your project directory. Try running the code from the terminal.
Sometimes it happens due to the changes in the format of your excel file. Make sure that the excel file is saved as CVS.
So I tried to run this code.
import pandas
i = input("hi input a csv file..")
df = pandas.read_csv(i)
and I got an error saying
FileNotFoundError: File b'"C:\\Users\\thomas.swenson\\Downloads\\hi.csv"' does not exist
but then if I hard code that path that 'doesn't exist' into my program it works fine.
import pandas
df = pandas.read_csv("C:\\Users\\thomas.swenson\\Downloads\\hi.csv")
it works just fine.
Anyone know why this may be happening?
I'm running python 3.6 and using a virtualenv
looks like the input function was placing another set of quotes around the input.
so ill just have to remove them and it works fine.
I'm trying to read a file using python and I keep getting this error
ERROR: Line magic function `%user_vars` not found.
My code is very basic just
names = read_csv('Combined data.csv')
names.head()
I get this for anytime I try to read or open a file. I tried using this thread for help.
ERROR: Line magic function `%matplotlib` not found
I'm using enthought canopy and I have IPython version 2.4.1. I made sure to update using the IPython installation page for help. I'm not sure what's wrong because it should be very simple to open/read files. I even get this error for opening text files.
EDIT:
I imported traceback and used
print(traceback.format_exc())
But all I get is none printed. I'm not sure what that means.
Looks like you are using Pandas. Try the following (assuming your csv file is in the same path as the your script lib) and insert it one line at a time if you are using the IPython Shell:
import pandas as pd
names = pd.read_csv('Combined data.csv')
names.head()