我试图通过雅虎拉出盘中aapl股票数据。但是我面对我的计划有问题..
import pandas as pd
import datetime
import urllib2
import matplotlib.pyplot as plt
get = 'http://chartapi.finance.yahoo.com/instrument/1.0/aapl/chartdata;type=quote;range=1d/csv'
getdata = urllib2.urlopen(get).read()
df = pd.read_csv(getdata, skiprows=17, header=None)
print df.head()
错误就是这个......
Traceback (most recent call last):
File "getyahoodata.py", line 10, in <module>
df = pd.read_csv(getdata, skiprows=16, header=None)
File "/usr/lib/python2.7/dist-packages/pandas/io/parsers.py", line 420, in parser_f
return _read(filepath_or_buffer, kwds)
File "/usr/lib/python2.7/dist-packages/pandas/io/parsers.py", line 218, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "/usr/lib/python2.7/dist-packages/pandas/io/parsers.py", line 502, in __init__
self._make_engine(self.engine)
File "/usr/lib/python2.7/dist-packages/pandas/io/parsers.py", line 610, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "/usr/lib/python2.7/dist-packages/pandas/io/parsers.py", line 972, in __init__
self._reader = _parser.TextReader(src, **kwds)
File "parser.pyx", line 330, in pandas.parser.TextReader.__cinit__ (pandas/parser.c:3200)
File "parser.pyx", line 557, in pandas.parser.TextReader._setup_parser_source (pandas/parser.c:5559)
IOError: File uri:/instrument/1.0/aapl/chartdata;type=quote;range=1d/csv
代码:AAPL
1413811857,98.3800,98.4999,98.3000,98.3800,1327900
1413811908,98.5200,98.6196,98.3360,98.3800,380100
1413811978,98.4200,98.5300,98.3850,98.4700,993800
:::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::
more and more
1413835019,99.8800,99.9100,99.8600,99.9000,524300
1413835079,99.8600,99.8850,99.8500,99.8700,600400
1413835139,99.8100,99.8600,99.7900,99.8500,530900
1413835199,99.7201,99.8301,99.7000,99.8200,1001500
1413835200,99.7600,99.7600,99.7600,99.7600,1720500
不存在
在雅虎数据拉动程序显示完整数据...但当我使用谷歌它工作完美...请尝试以上程序帮助编写程序...谢谢...
答案 0 :(得分:3)
pd.read_csv
接受路径或类似文件的对象。您正在传递文本本身,并且尝试将其作为文件名读取。您可以直接传递该网址(虽然get
不是一个很棒的变量名称。)
In [102]: df = pd.read_csv(get, skiprows=17, header=None)
In [103]: df.head()
Out[103]:
0 1 2 3 4 5
0 1413811859 98.3800 98.5000 98.3100 98.4800 1348400
1 1413811860 98.4775 98.6196 98.3265 98.3701 452200
2 1413811977 98.4250 98.5400 98.3800 98.4700 900000
3 1413812039 98.4800 98.4900 98.3900 98.4250 378100
4 1413812040 98.8300 98.8500 98.4700 98.4800 495300