繁体   English   中英

允许用户选择以确定web.DataReader中的库存选择

[英]Allow user selection to determine the stock selection in web.DataReader

我正在寻找一个程序,它将使用用户选择的股票并使用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()

结果与

web.DataReader语句中的input(“”)

OSError:3次尝试后,Yahoo! 没有为网址返回200'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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM