原子无法读取与熊猫同目录的csv

时间:2019-10-20 13:46:42

标签: python pandas csv atom-editor

CSV文件和.py文件位于其他目录下的同一目录中。

upper_directory
 - lower_directory
    - test.py (where I read the csv file from)
    - student_data.csv

我尝试什么:

import pandas as pd
df = pd.read_csv('student_data.csv')

我得到的是:

Traceback (most recent call last):
  File "/Users/iwasiwas/Desktop/flask_dash_directory/myproject/dashboard/test.py", line 3, in <module>
    df = pd.read_csv("student_data.csv")
  File "/Users/iwasiwas/anaconda3/lib/python3.7/site-packages/pandas/io/parsers.py", line 702, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "/Users/iwasiwas/anaconda3/lib/python3.7/site-packages/pandas/io/parsers.py", line 429, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "/Users/iwasiwas/anaconda3/lib/python3.7/site-packages/pandas/io/parsers.py", line 895, in __init__
    self._make_engine(self.engine)
  File "/Users/iwasiwas/anaconda3/lib/python3.7/site-packages/pandas/io/parsers.py", line 1122, in _make_engine
    self._engine = CParserWrapper(self.f, **self.options)
  File "/Users/iwasiwas/anaconda3/lib/python3.7/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'student_data.csv' does not exist: b'student_data.csv'

如何在不输入完整路径的情况下解决此问题? (它可以与完整版本一起使用-但我需要在没有本地完整部署路径的情况下使其正常工作,而且我不明白为什么它不起作用,因为.py文件和.csv文件都位于同一目录中)

谢谢!

0 个答案:

没有答案