1

我正在使用 zipline 中的 csvdir 包加载 csv 文件。它给出了“ValueError:在位置 0 解析日期时间字符串“A.csv”时出错”错误。如何解决?

当我直接使用熊猫加载它时,它加载得很好:

>>> Acsv = pd.read_csv("D:/work/tmp/hData/bundles/data/NYSE_dat/A.csv", parse_dates=[0], infer_datetime_format=True, index_col=0)
>>> Acsv.head()
             open   high    low  close   volume  dividend  split
date                                                            
2014-06-18  58.86  59.32  58.53  59.27  1114700       0.0    1.0
2014-06-19  59.20  59.54  58.15  58.62  3149500       0.0    1.0
2014-06-20  57.95  59.06  57.84  58.77  2027500       0.0    1.0
2014-06-23  58.71  58.86  57.97  58.11  1435600       0.0    1.0
2014-06-24  58.03  58.49  57.58  57.65  1125800       0.0    1.0

这是代码的代码错误:

>>> CSV_BUNDLE_NAME = 'NYSE_dat'
>>> from zipline.data import bundles
>>> os.environ['ZIPLINE_ROOT'] = "D:/work/tmp/hData/bundles" 
>>> injst_func = bundles.csvdir.csvdir_equities(['daily'], CSV_BUNDLE_NAME)
>>> bundles.register(CSV_BUNDLE_NAME, injst_func)
<bound method CSVDIRBundle.ingest of <zipline.data.bundles.csvdir.CSVDIRBundle object at 0x000000001CFC82E8>>
>>> bundle_data = bundles.load(CSV_BUNDLE_NAME)
Traceback (most recent call last):
  File "pandas/_libs/tslib.pyx", line 1702, in pandas._libs.tslib.convert_str_to_tsobject
  File "pandas/_libs/src/datetime.pxd", line 119, in datetime._string_to_dts
ValueError: Error parsing datetime string "A.csv" at position 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pandas/_libs/tslib.pyx", line 1732, in pandas._libs.tslib.convert_str_to_tsobject
  File "pandas/_libs/tslibs/parsing.pyx", line 99, in pandas._libs.tslibs.parsing.parse_datetime_string
  File "C:\Users\Raja\.conda\envs\TradingEnv\lib\site-packages\dateutil\parser\_parser.py", line 1356, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
  File "C:\Users\Raja\.conda\envs\TradingEnv\lib\site-packages\dateutil\parser\_parser.py", line 648, in parse
    raise ValueError("Unknown string format:", timestr)
ValueError: ('Unknown string format:', 'A.csv')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Raja\.conda\envs\TradingEnv\lib\site-packages\zipline\data\bundles\core.py", line 486, in most_recent_data
    key=from_bundle_ingest_dirname,
  File "C:\Users\Raja\.conda\envs\TradingEnv\lib\site-packages\zipline\data\bundles\core.py", line 123, in from_bundle_ingest_dirname
    return pd.Timestamp(cs.replace(';', ':'))
  File "pandas/_libs/tslib.pyx", line 390, in pandas._libs.tslib.Timestamp.__new__
  File "pandas/_libs/tslib.pyx", line 1549, in pandas._libs.tslib.convert_to_tsobject
  File "pandas/_libs/tslib.pyx", line 1735, in pandas._libs.tslib.convert_str_to_tsobject
ValueError: could not convert string to Timestamp

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Raja\.conda\envs\TradingEnv\lib\site-packages\zipline\data\bundles\core.py", line 521, in load
    timestr = most_recent_data(name, timestamp, environ=environ)
  File "C:\Users\Raja\.conda\envs\TradingEnv\lib\site-packages\zipline\data\bundles\core.py", line 497, in most_recent_data
    timestamp=timestamp,
ValueError: no data for bundle 'NYSE_dat' on or before 2019-07-10 03:03:42.161500+00:00
maybe you need to run: $ zipline ingest -b NYSE_dat
4

0 回答 0