简体   繁体   English

Python:使用Pandas导入CSV文件时出现ID错误

[英]Python: ID error when importing csv file with pandas

I am trying to Import a csv file saved in a local Folder. 我正在尝试导入保存在本地文件夹中的csv文件。 When I use Anaconda Python Notebook I have no Problems, while using Zeppelin I do have issues. 当我使用Anaconda Python Notebook时,我没有问题,而在使用Zeppelin时,我确实有问题。 The code I am using, that works fine in Anaconda, is: 我正在使用的代码在Anaconda中可以正常工作,它是:

#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: 但是,在Zeppelin上运行它时,我收到:

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 ) Traceback让您知道python解释器正在Unix文件路径模式下运行( /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下时,您位于纯Windows中,因此回溯将类似于( 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. Anaconda将使用Windows类型的文件路径访问文件,Zeppelin将使用UNIX类型的文件路径访问文件。

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: 您的问题肯定与在Zeppelin中指定路径有关 ,您不能使用Windows路径,但是您可以尝试如下操作:

frequency=pd.read_csv("file:///C:/Users/L18938/Desktop/Vehicle_to_grid/analysis/Frequency_March_2018.csv", nrows=86401)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM