Pandas数据读取器错误

2024-09-30 05:17:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经成功地使用这样的脚本几个月来使用谷歌作为数据提供者。几天前它停止工作了。输入如下:

import numpy as np
import pandas as pd
import pandas_datareader.data as wb
from datetime import date, datetime, time, timedelta
from pandas.tseries.offsets import BDay

data_provider = 'google' # 'google', 'quandl', or 'yahoo'

today = date.today()
four_days_ago = today - BDay (4)

tickers = [{'ACET':1},{'HBAN':2},{'HPQ':3},{'IPG':4},{'AOSL':5},{'HBI':6},{'NRG':7},{'IBM':8},{'MMM':9}]

enter_list = []
rank_list = []

for x in tickers:
    for ticker, rank in x.items():
        try:
            df = wb.DataReader (ticker, data_provider, four_days_ago, today)
            print ('reading data for ' + ticker + ' from ' + data_provider)
        except:
            print ('\ncan not read data for ' + ticker + ' from ' + data_provider)

        if df.iloc[1]['Low'] < df.iloc[0]['Low']:
            enter_list.append (ticker)
            rank_list.append (rank)

df2 = pd.DataFrame({'ticker' : enter_list, 'rank' : rank_list}, columns = ['ticker', 'rank'])

if len(df2) == 0:
    print ('\nthere are no qualifying stocks')
else:
    print ('\nlower stocks\n')
    print (df2)

输出如下:

^{pr2}$

以下是数据提供程序为quandl时的输出:

reading data for ACET from quandl
reading data for HBAN from quandl
reading data for HPQ from quandl
reading data for IPG from quandl
reading data for AOSL from quandl

can not read data for HBI from quandl
reading data for NRG from quandl
reading data for IBM from quandl
reading data for MMM from quandl

lower stocks

  ticker  rank
0   HBAN     2
1    IPG     4
2    IBM     8
3    MMM     9

以下是数据读取器为yahoo时的输出:

reading data for ACET from yahoo
reading data for HBAN from yahoo
reading data for HPQ from yahoo
reading data for IPG from yahoo
reading data for AOSL from yahoo
reading data for HBI from yahoo
reading data for NRG from yahoo

can not read data for IBM from yahoo
reading data for MMM from yahoo

lower stocks

  ticker  rank
0   HBAN     2
1    HPQ     3
2    IPG     4
3   AOSL     5
4    HBI     6
5    NRG     7
6    IBM     8

雅虎的输出在运行时会发生变化。下面是一些后续输出:

reading data for ACET from yahoo
reading data for HBAN from yahoo
reading data for HPQ from yahoo
reading data for IPG from yahoo
reading data for AOSL from yahoo
reading data for HBI from yahoo
reading data for NRG from yahoo
reading data for IBM from yahoo
reading data for MMM from yahoo

lower stocks

  ticker  rank
0   HBAN     2
1    HPQ     3
2    IPG     4
3   AOSL     5
4    HBI     6
5    NRG     7

有人知道这里发生了什么吗? 这个问题是由于用一个循环创建多个数据帧引起的吗? ping服务器的问题是否太多/太快?在

提前谢谢你, 大卫


Tags: fromfordataibmyahootickerrankquandl

热门问题