2017-03-05 109 views
0
import pandas as pd 
df=pd.read_csv(r"C:\Users\champion\Desktop\政大資料科學競賽\104.1~106.1\臺北捷運各站出站量統計_201501.csv",encoding='big5') 

我可以执行它我不知道为什么Python会发生OSError。为什么我无法打开我的文件?

这可能是我的数据是中文吗?

我浏览了很多问题,但没有人不能回答我。

--------------------------------------------------------------------------- 
OSError         Traceback (most recent call last) 
<ipython-input-9-0dfa88abff19> in <module>() 
----> 1 df=pd.read_csv(r'C:\Users\champion\Desktop\政大資料科學競賽\104.1~106.1\臺北捷運各站出站量統計_201503.csv') 

D:\anoconda3\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) 
    644      skip_blank_lines=skip_blank_lines) 
    645 
--> 646   return _read(filepath_or_buffer, kwds) 
    647 
    648  parser_f.__name__ = name 

D:\anoconda3\lib\site-packages\pandas\io\parsers.py in _read(filepath_or_buffer, kwds) 
    387 
    388  # Create the parser. 
--> 389  parser = TextFileReader(filepath_or_buffer, **kwds) 
    390 
    391  if (nrows is not None) and (chunksize is not None): 

D:\anoconda3\lib\site-packages\pandas\io\parsers.py in __init__(self, f, engine, **kwds) 
    728    self.options['has_index_names'] = kwds['has_index_names'] 
    729 
--> 730   self._make_engine(self.engine) 
    731 
    732  def close(self): 

D:\anoconda3\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine) 
    921  def _make_engine(self, engine='c'): 
    922   if engine == 'c': 
--> 923    self._engine = CParserWrapper(self.f, **self.options) 
    924   else: 
    925    if engine == 'python': 

D:\anoconda3\lib\site-packages\pandas\io\parsers.py in __init__(self, src, **kwds) 
    1388   kwds['allow_leading_cols'] = self.index_col is not False 
    1389 
-> 1390   self._reader = _parser.TextReader(src, **kwds) 
    1391 
    1392   # XXX 

pandas\parser.pyx in pandas.parser.TextReader.__cinit__ (pandas\parser.c:4184)() 

pandas\parser.pyx in pandas.parser.TextReader._setup_parser_source (pandas\parser.c:8471)() 



OSError: Initializing from file failed 

OSERROR:从文件初始化失败,则意味着我的系统是错误的?

+0

它的工作原理,如果路径到您的文件和文件名不包含ASCII字符?例如'r“C:\ Users \ champion \ Desktop \ foo \ 104.1〜106.1 \ bar_201501.csv”'(它可能有助于知道您正在使用哪个版本的python) – snakecharmerb

+0

以下命令是否工作:open( R “C:\用户\冠军\桌面\政大资料科学竞赛\ 104.1〜106.1 \台北捷运各站出站量统计_201501.csv”')'? – MaxU

+0

看到[这个问题](https://stackoverflow.com/questions/44256868/pandas-oserror-with-accent-special-character-in-file-path-and-file-name),这可能是同样的问题 – elzell

回答

-1

如果妳使用Python 3.6,U可以尝试

df=pd.read_csv(r"C:\Users\champion\Desktop\政大資料科學競賽\104.1~106.1\臺北捷運各站出站量統計_201501.csv",encoding='big5',engine="python")