允许用户选择确定 web.DataReader 中的股票选择

Allow user selection to determine the stock selection in web.DataReader

我想创建一个程序,将获取用户选择的股票和 return 使用 Pandas 中的 web.DataReader 函数的信息。任何建议或替代解决方案将不胜感激。

import pandas as pd
import pandas.io.data as web   # Package and modules for importing data; this code may change depending on pandas version
import datetime

start = datetime.datetime(2016,1,1)
end = datetime.date.today()

apple = web.DataReader(input(""), "yahoo", start, end)

type(apple)
apple.head()

结果

input("") in web.DataReader statement

OSError: after 3 tries, Yahoo! did not return a 200 for url 'http://ichart.finance.yahoo.com/table.csv?s=appl&a=0&b=1&c=2016&d=11&e=8&f=2016&g=d&ignore=.csv'

既然数据阅读器已经移到他们自己的包中,那么您应该如何真正做到这一点。您还需要提供有效的代码,如果是苹果,则为 AAPL 而不是 appl

import pandas as pd
from pandas_datareader import data, wb
import datetime

start = datetime.datetime(2016,1,1)
end = datetime.date.today()

apple = data.DataReader(input("Please Input the name of the Ticker:\n"), "yahoo", start, end)

type(apple)
apple.head()

Please Input the name of the Ticker:
AAPL

    Open    High    Low     Close   Volume  Adj Close
Date                        
2016-01-04  102.610001  105.370003  102.000000  105.349998  67649400    103.057063
2016-01-05  105.750000  105.849998  102.410004  102.709999  55791000    100.474523
2016-01-06  100.559998  102.370003  99.870003   100.699997  68457400    98.508268
2016-01-07  98.680000   100.129997  96.430000   96.449997   81094400    94.350769
2016-01-08  98.550003   99.110001   96.760002   96.959999   70798000    94.849671