【问题标题】:Yahoo forex dates are off?雅虎外汇日期关闭?
【发布时间】:2018-01-06 14:18:07
【问题描述】:

DataReader 或 Yahoo 数据本身都有问题:

start = datetime.datetime(2012,9,27)
end   = datetime.datetime(2013,12,31)
n = 'GBPUSD=X'
us = web.DataReader(n, 'yahoo', start, end)
us.Close

Date
2012-09-25    1.619433
2012-09-26    1.617861
2012-09-27    1.623298
2012-09-30    1.612487
2012-10-01    1.612903
2012-10-02    1.613163
2012-10-03    1.610047
2012-10-04    1.618647
2012-10-07    1.613892
2012-10-08    1.603412
2012-10-09    1.599693
....

(2012-09-28 星期五在哪里?)

(2012-10-05 星期五在哪里?)

似乎数据已关闭。它们包括星期日但不包括星期五? 另外,我要的是 9 月 27 日,但第一个日期是 9 月 25 日?

发生了什么事? 谁有线索?

(似乎几周后工作日又恢复同步了。我该如何调整已关闭的几周?)

【问题讨论】:

    标签: python yahoo datareader forex


    【解决方案1】:

    似乎星期是随机关闭的,雅虎的数据确实有问题。

    这是生成具有正确数据和日期的新数据框的方法:

    #generate a new range of dates
    dates = p.bdate_range(p.to_datetime('2012-01-01', format='%Y-%m-%d'), periods=330)
    #get the column names from the old data frame
    colnames = db.columns.get_values()
    coln = colnames.tolist()
    #generate a new data frame with values and column names from the old data frame (db), the new dates (dates)
    newdb = p.DataFrame(db.values, dates, columns=coln).set_index(dates)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-23
      • 2016-06-15
      • 1970-01-01
      • 2011-01-02
      • 2021-09-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多