2016-12-08 8 views
0

私は、ユーザーが選択した株式を取得するプログラムを作成し、 パンダのweb.DataReader関数を使用して情報を返します。任意の提案や代替のソリューションをいただければ幸いです。web.DataReaderの在庫選択をユーザーが選択できるようにする

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 '

+1

はすなわち、関数の外に、前に 'input'のコマンドを実行してみます、有効なティッカーを提供する必要がありますか? – IanS

+2

入力した内容を 'input(" ")'で表示できますか? –

+0

@イアンズ、良いアイデア、私はそれが働いている! – aselya

答えて

1

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() 

結果は、ここであなたが本当にデータの読者が自分のパッケージに移動されたことを、今それを行う必要がある方法です。あなたはまた、リンゴの場合、それ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 
関連する問題