Jupyter笔记本/Pandas目录

2024-05-08 04:20:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我最近在Anaconda中创建了一个新环境,以便下载python3.6。我遇到的麻烦是在jupyter/pandas中路由目录,这样我就可以轻松地访问我的csv文件。即使我输入csv文件的直接路径,熊猫也无法读取它。我在Anaconda创造了一个新的环境,但我不确定它会是什么。有人有这方面的经验吗?你知道吗

    df_returns=pd.read_csv('returns.csv')
    FileNotFoundError: File b'returns.csv' does not exist



-------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-5-20c52d2b09e4> in <module>()
----> 1 df_returns=pd.read_csv('returns.csv')

c:\users\philz\anaconda\envs\py36\lib\site-packages\pandas\io\parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, skip_footer, doublequote, delim_whitespace, as_recarray, compact_ints, use_unsigned, low_memory, buffer_lines, memory_map, float_precision)
    707                     skip_blank_lines=skip_blank_lines)
    708 
--> 709         return _read(filepath_or_buffer, kwds)
    710 
    711     parser_f.__name__ = name

c:\users\philz\anaconda\envs\py36\lib\site-packages\pandas\io\parsers.py in _read(filepath_or_buffer, kwds)
    447 
    448     # Create the parser.
--> 449     parser = TextFileReader(filepath_or_buffer, **kwds)
    450 
    451     if chunksize or iterator:

c:\users\philz\anaconda\envs\py36\lib\site-packages\pandas\io\parsers.py in __init__(self, f, engine, **kwds)
    816             self.options['has_index_names'] = kwds['has_index_names']
    817 
--> 818         self._make_engine(self.engine)
    819 
    820     def close(self):

c:\users\philz\anaconda\envs\py36\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine)
   1047     def _make_engine(self, engine='c'):
   1048         if engine == 'c':
-> 1049             self._engine = CParserWrapper(self.f, **self.options)
   1050         else:
   1051             if engine == 'python':

c:\users\philz\anaconda\envs\py36\lib\site-packages\pandas\io\parsers.py in __init__(self, src, **kwds)
   1693         kwds['allow_leading_cols'] = self.index_col is not False
   1694 
-> 1695         self._reader = parsers.TextReader(src, **kwds)
   1696 
   1697         # XXX

pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.__cinit__()

pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source()

FileNotFoundError: File b'returns.csv' does not exist

Tags: csvinselfparserpandasanacondausersengine
2条回答

尝试将完整路径与操作系统健壮的路径分隔符一起使用。基本上用^{}构建路径:

import os
my_path = os.path.join('path', 'to', 'my', 'file.csv')
df = pd.read_csv(my_path)

您可以使用csv的完全限定路径

import pandas as pd

full_path = 'c:\\users\\philz\\path\\to\\returns.csv'
df_returns = pd.read_csv(full_path)

相关问题 更多 >