python pandas 雅虎股票数据错误 [英] python pandas yahoo stock data error

查看:62
本文介绍了python pandas 雅虎股票数据错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 yahoo 提取日内 aapl 股票数据.但是我的程序遇到了问题..

i am try to pullout intraday aapl stock data by yahoo. but there problem i facing with my program..

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

不存在

在雅虎数据拉取程序中显示完整数据...但是当我使用谷歌时它工作得很好...请尝试上面的程序帮助编写程序...谢谢...

in yahoo data pulling program show full data...but when i am useing google it work perfect...please try above program help to write program...thanks...

推荐答案

pd.read_csv 接受路径或类似文件的对象.您正在传递文本本身,它试图将其作为文件名读取.您可以只传递 URL(尽管 get 不是一个很好的变量名称..)

pd.read_csv accepts a path or a filelike object. You're passing the text itself, and it's trying to read that as a filename. You can just pass the URL (although get isn't a great variable name..)

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

这篇关于python pandas 雅虎股票数据错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆