data = pd.read_csv(datafile,encoding = 'utf-8')
Traceback (most recent call last):
File "", line 1, in
data = pd.read_csv(datafile,encoding = 'utf-8')
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 709, in parser_f
return _read(filepath_or_buffer, kwds)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 449, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 818, in __init__
self._make_engine(self.engine)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 1049, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 1695, in __init__
self._reader = parsers.TextReader(src, **kwds)
File "pandas/_libs/parsers.pyx", line 402, in pandas._libs.parsers.TextReader.__cinit__
File "pandas/_libs/parsers.pyx", line 720, in pandas._libs.parsers.TextReader._setup_parser_source
OSError: Initializing from file failed
解决方法
import os
pwd = os.getcwd()
os.chdir(os.path.dirname(datafile))
data = pd.read_csv(os.path.basename(datafile),encoding = 'utf-8')
os.chdir(pwd)
data