ParserError:标记数据时出错。 (tradingWithPython库) - 在一台计算机上运行,​​而不是在其他计算机上运行

时间:2018-02-09 03:32:32

标签: python pandas

我有两台计算机都运行带有Jupyter Notebook的Python 3。我在两者上都安装了tradingWithPython库。我试图在每台计算机上运行以下命令:

data = twp.yahooFinance.getHistoricData('SPY')

在一台计算机上它完美运行(告诉我yahooFinance库很好)。在另一台计算机上,我收到以下错误。有人可以帮我解决这个问题吗?我错过了图书馆吗?

---------------------------------------------------------------------------
ParserError                               Traceback (most recent call last)
<ipython-input-2-18d2ebb8dde1> in <module>()
----> 1 data = twp.yahooFinance.getHistoricData('SPY')

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tradingWithPython/lib/yahooFinance.py in getHistoricData(symbols, **options)
    121 
    122     if isinstance(symbols,str):
--> 123         return getSymbolData(symbols,**options)
    124     else:
    125         data = {}

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tradingWithPython/lib/yahooFinance.py in getSymbolData(symbol, sDate, adjust, verbose)
    163 
    164     buf = io.StringIO(data.text) # create a buffer
--> 165     df = pd.read_csv(buf,index_col=0,parse_dates=True) # convert to pandas DataFrame
    166 
    167     # rename columns

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/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

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/io/parsers.py in _read(filepath_or_buffer, kwds)
    453 
    454     try:
--> 455         data = parser.read(nrows)
    456     finally:
    457         parser.close()

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/io/parsers.py in read(self, nrows)
   1067                 raise ValueError('skipfooter not supported for iteration')
   1068 
-> 1069         ret = self._engine.read(nrows)
   1070 
   1071         if self.options.get('as_recarray'):

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/io/parsers.py in read(self, nrows)
   1837     def read(self, nrows=None):
   1838         try:
-> 1839             data = self._reader.read(nrows)
   1840         except StopIteration:
   1841             if self._first_chunk:

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

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

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

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

pandas/_libs/parsers.pyx in pandas._libs.parsers.raise_parser_error()

ParserError: Error tokenizing data. C error: Expected 1 fields in line 4, saw 2

1 个答案:

答案 0 :(得分:0)

尝试完所有内容(重新安装Python 3,卸载/重新安装Pandas,tradingWithPython和其他一些库)后,什么都行不通。但是,我可以让它在其他计算机上工作。我决定核对我的新电脑(擦除硬盘驱动器重新安装的操作系统)并重新开始。这解决了这个问题,图书馆现在运作良好,没有任何问题。我不确定是什么导致了冲突,但我很高兴它现在正在运作。

当我安装其他软件时,手指越过这个问题并没有回来。