Python: ID error when importing csv file with pandas - python

I am trying to Import a csv file saved in a local Folder. When I use Anaconda Python Notebook I have no Problems, while using Zeppelin I do have issues.
The code I am using, that works fine in Anaconda, is:
#import csv data
frequency=pd.read_csv("C:\\Users\\L18938\\Desktop\\Vehicle_to_grid\\analysis\\Frequency_March_2018.csv", nrows=86401)
However, when running it on Zeppelin, I receive:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.py", line 646, in parser_f
return _read(filepath_or_buffer, kwds)
File "/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.py", line 389, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.py", line 730, in __init__
self._make_engine(self.engine)
File "/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.py", line 923, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.py", line 1390, in __init__
self._reader = _parser.TextReader(src, **kwds)
File "pandas/parser.pyx", line 373, in pandas.parser.TextReader.__cinit__ (pandas/parser.c:4025)
File "pandas/parser.pyx", line 667, in pandas.parser.TextReader._setup_parser_source (pandas/parser.c:8031)
IOError: File C:\Users\L18938\Desktop\Vehicle_to_grid\analysis\Frequency_March_2018.csv does not exist
Obviously, the file exists and there are no Errors in the path spelling.
I have tryied / or double \, but nothing changes. Also
os.chdir("C:/Users/L18938/Desktop/Vehicle_to_grid/analysis")
or
os.listdir("C:/Users/L18938/Desktop/Vehicle_to_grid/analysis")
Any idea? thank you in advance

Your Traceback let show you that the python interpreter is running in Unix file path mode (/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.py)
When you are under Anaconda, you are in pure windows and your traceback will be something like (C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parsers.py)
Anaconda will reach file with a Windows type file-path, and Zeppelin will reach file in a UNIX type file-path.
Your issue is definitely relative to how you specify your path in Zeppelin, you can't use Windows path, but you you may try something like that:
frequency=pd.read_csv("file:///C:/Users/L18938/Desktop/Vehicle_to_grid/analysis/Frequency_March_2018.csv", nrows=86401)

Related

Python SLEEPPY demo gets IOError: "sleep_endpoints_summary.csv does not exist"

Full error is:
IOError: File C:\PRIMARY\WORK\wearable\SLEEPPY\RESULTS/demo/sleep_endpoints/sleep_endpoints_summary.csv does not exist
Also: directory SLEEPPY\RESULTS/demo/ is missing.
Is intermixing backslashes and foreslashes a problem?
...and it is missing directory: SLEEPPY\RESULTS/demo/
Directory "C:\PRIMARY\WORK\wearable\SLEEPPY\RESULTS" exists.
I get the IOError when I do "Running the demo files" after I installed https://github.com/elyiorgos/sleeppy sleep measurement.
I'm running on Windows 10 Python 2.7.18
Full output, with error at end...
>>> import sleeppy.tests as demo
>>> demo.run_demo()
Please provide a path to a results directory: C:\PRIMARY\WORK\wearable\SLEEPPY\RESULTS
Loading data...
Error processing: c:\Python27\lib\site-packages\sleeppy\tests\demo.bin
Error: ``C:\PRIMARY\WORK\wearable\SLEEPPY\RESULTS/c:\Python27\lib\site-packages\sleeppy\tests\demo/raw_days/c:\Python27\lib\site-packages\sleeppy\tests`` does not exist
total run time: 6.7197999994 minutes
Checking endpoints...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Python27\lib\site-packages\sleeppy\tests\demo.py", line 37, in run_demo
obtained = collect_endpoints(dst)
File "c:\Python27\lib\site-packages\sleeppy\tests\demo.py", line 43, in collect_endpoints
return pd.read_csv(src).values[0]
File "c:\Python27\lib\site-packages\pandas\io\parsers.py", line 678, in parser_f
return _read(filepath_or_buffer, kwds)
File "c:\Python27\lib\site-packages\pandas\io\parsers.py", line 440, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "c:\Python27\lib\site-packages\pandas\io\parsers.py", line 787, in __init__
self._make_engine(self.engine)
File "c:\Python27\lib\site-packages\pandas\io\parsers.py", line 1014, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "c:\Python27\lib\site-packages\pandas\io\parsers.py", line 1708, in __init__
self._reader = parsers.TextReader(src, **kwds)
File "pandas\_libs\parsers.pyx", line 384, in pandas._libs.parsers.TextReader.__cinit__
File "pandas\_libs\parsers.pyx", line 695, in pandas._libs.parsers.TextReader._setup_parser_source
IOError: File C:\PRIMARY\WORK\wearable\SLEEPPY\RESULTS/demo/sleep_endpoints/sleep_endpoints_summary.csv does not exist
>>>
Well, the answer so far is me having to debug github sleeppy for Windows 10.
First, there was init problem with results path.
Next, def split_days_geneactiv_bin crashed with ioerror...

Cannot use relative path when using 'Execute Line in Console' in Pycharm

I'm using Pycharm for python project. My project structure is like this:
+ project
+ src
- Data.csv
- main.py
This is main.py:
import panda as pd
dataset = pd.read_csv("Data.csv")
When i use 'Execute Line in Console' and run the second line, i get this error:
Traceback (most recent call last):
File "C:\Users\livw2\AppData\Local\Programs\Python\Python37\lib\site-packages\IPython\core\interactiveshell.py", line 3296, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-14-bd7168d85704>", line 1, in <module>
dataset = pd.read_csv('Data.csv')
File "C:\Users\livw2\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 702, in parser_f
return _read(filepath_or_buffer, kwds)
File "C:\Users\livw2\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 429, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "C:\Users\livw2\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 895, in __init__
self._make_engine(self.engine)
File "C:\Users\livw2\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 1122, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "C:\Users\livw2\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 1853, in __init__
self._reader = parsers.TextReader(src, **kwds)
File "pandas\_libs\parsers.pyx", line 387, in pandas._libs.parsers.TextReader.__cinit__
File "pandas\_libs\parsers.pyx", line 705, in pandas._libs.parsers.TextReader._setup_parser_source
FileNotFoundError: [Errno 2] File b'Data.csv' does not exist: b'Data.csv'
When i run the whole code using 'Run', it's fine, so i think that executing in console changes the directory. But i haven't figured out how to fix.
To fix it, just close your current project and open another project which contain your file directly.

Python : FileNotFoundError: File b'fleet.csv' does not exist

I am getting a FileNotFoundError when I try to read a particular CSV file in the directory.
If i read another CSV file, I can read it properly without any error.
What I have tried
fleet_data=pd.read_csv('data_fleet.csv', sep=',',index_col=0)
fleet_data=pd.read_csv('Users/Ver/Desktop/Processing/data_fleet.csv',sep=',',index_col=0)
fleet_data=pd.read_csv('Users\Ver\Desktop\Processing\data_fleet.csv',sep=',',index_col=0)
fleet_data=pd.read_csv('data_fleet.csv')
I tried changing the name of the file, but it still doesn't work.
Error
fleet_data=pd.read_csv('data_fleet.csv', sep=',',index_col=0)
Traceback (most recent call last):
File "C:\Users\VW3ZTWS\PycharmProjects\Data_Collection_and_learnings\venv\lib\site-packages\IPython\core\interactiveshell.py", line 2869, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-36-9aab06bbbbcc>", line 1, in <module>
fleet_data=pd.read_csv('data_fleet.csv', sep=',',index_col=0)
File "C:\Users\VW3ZTWS\PycharmProjects\Data_Collection_and_learnings\venv\lib\site-packages\pandas\io\parsers.py", line 678, in parser_f
return _read(filepath_or_buffer, kwds)
File "C:\Users\VW3ZTWS\PycharmProjects\Data_Collection_and_learnings\venv\lib\site-packages\pandas\io\parsers.py", line 440, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "C:\Users\VW3ZTWS\PycharmProjects\Data_Collection_and_learnings\venv\lib\site-packages\pandas\io\parsers.py", line 787, in __init__
self._make_engine(self.engine)
File "C:\Users\VW3ZTWS\PycharmProjects\Data_Collection_and_learnings\venv\lib\site-packages\pandas\io\parsers.py", line 1014, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "C:\Users\VW3ZTWS\PycharmProjects\Data_Collection_and_learnings\venv\lib\site-packages\pandas\io\parsers.py", line 1708, in __init__
self._reader = parsers.TextReader(src, **kwds)
File "pandas\_libs\parsers.pyx", line 384, in pandas._libs.parsers.TextReader.__cinit__
File "pandas\_libs\parsers.pyx", line 695, in pandas._libs.parsers.TextReader._setup_parser_source
FileNotFoundError: File b'data_fleet.csv' does not exist
But
If I copy the CSV file from the project to another project folder and open the Python file and open the file (data_fleet.py), I can read it without any issues.
What is the issue in reading the file in a desired folder?
Try to give it absolute path:
'C:\\Users\\Ver\\Desktop\\Processing\\data_fleet.csv'
Could you try listing the content of your directory? For example using the os module and the listdir() function
>>> import os
>>> contents = os.listdir()
>>> contents
This will let you see if there is any odd characters or something preventing you from "finding it"

I am getting error when opening a CSV file in pycharm

I am using pycharm and when i run a code of opening a csv file using pandas I am getting an error of no existence.
I saved the csv file in my project directory and called it using pandas.
import pandas as pd
df = pd.read_csv("E:\\students")
print(df)
The error when i run the code:
Traceback (most recent call last): File "E:/untitled232/file1.py", line 2, in <module>
df = pd.read_csv("E:\\students") File "E:\untitled232\venv\lib\site-packages\pandas\io\parsers.py", line 678, in parser_f
return _read(filepath_or_buffer, kwds) File "E:\untitled232\venv\lib\site-packages\pandas\io\parsers.py", line 440, in _read
parser = TextFileReader(filepath_or_buffer, **kwds) File "E:\untitled232\venv\lib\site-packages\pandas\io\parsers.py", line 787, in __init__
self._make_engine(self.engine) File "E:\untitled232\venv\lib\site-packages\pandas\io\parsers.py", line 1014, in _make_engine
self._engine = CParserWrapper(self.f, **self.options) File "E:\untitled232\venv\lib\site-packages\pandas\io\parsers.py", line 1708, in __init__
self._reader = parsers.TextReader(src, **kwds) File "pandas\_libs\parsers.pyx", line 384, in pandas._libs.parsers.TextReader.__cinit__ File "pandas\_libs\parsers.pyx", line 695, in pandas._libs.parsers.TextReader._setup_parser_source FileNotFoundError: File b'E:\\students' does not exist
It seems I had to put .csv after the name.

Python using .csv files in terminal

I wrote the following script that runs perfectly when using pyCharm, but when I go to run it in a terminal it gives me these errors:
File "/Users/Chris/PycharmProjects/firstfile/trial.py", line 6, in <module>
r = pf.read_csv('python.csv')
File "/usr/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 562, in parser_f
return _read(filepath_or_buffer, kwds)
File "/usr/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 315, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "/usr/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 645, in __init__
self._make_engine(self.engine)
File "/usr/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 799, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "/usr/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 1213, in __init__
self._reader = _parser.TextReader(src, **kwds)
File "pandas/parser.pyx", line 358, in pandas.parser.TextReader.__cinit__ (pandas/parser.c:3427)
File "pandas/parser.pyx", line 628, in pandas.parser.TextReader._setup_parser_source (pandas/parser.c:6861)
IOError: File python.csv does not exist
Could someone point in the the right direction? I am guessing that it has to do with the csv file not being in the right path or directory. Right now I have the csv file saved in the same folder as my .py project. I also checked and made sure I have the right packages installed, so I do not think it is that.
import csv
import pandas as pf
r = pf.read_csv('python.csv')
r.head()
print r.describe()
tradeDates = r['Trade Date'].unique()
r.name = 'Trade Date'
for trades in tradeDates:
outfilename = trades
printName = outfilename + ".csv"
print printName
r[r['Trade Date'] == trades].to_csv(printName, index=False)
When you run python /Users/Chris/PycharmProjects/firstfile/trial.py python looks for csv file in your current directory, not in /Users/Chris/PycharmProjects/firstfile.
You either need to change your directory before running the code, or you need to use the full path in trial.py like this:
import csv
import pandas as pf
r = pf.read_csv('/Users/Chris/PycharmProjects/firstfile/python.csv')
r.head()

Categories