python pandas yahoo stock data error

2024/11/18 9:27:05

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

and error is this....

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

ticker: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 more1413835019,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

does not exist

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...

Answer

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
https://en.xdnf.cn/q/118693.html

Related Q&A

Web Scraping Stock Ticker Price from Yahoo Finance using BeautifulSoup

Im trying to scrape Gold stock ticker from Yahoo! Finance. from bs4 import BeautifulSoup import requests, lxmlresponse = requests.get(https://finance.yahoo.com/quote/GC=F?p=GC=F) soup = BeautifulSoup(…

How to convert the radius from meter to pixel?

I have a camera with these specs:full resolution 1280x1024 pixel size 0.0048mm focal length 8 mmI need to detect a ball in this image. It is 4 meters away and its radius is 0.0373 meter. How to convert…

Calculting GPA using While Loop (Python)

A GPA, or Grade point Average, is calculated by summing the grade points earned in a student’s courses and then dividing by the total units. The grade points for an individual course are calculated by…

Return function that modifies the value of the input function

How can I make a function that is given a function as input and returns a function with the value tripled. Here is some pseudo code for what Im looking for. Concrete examples in Python or Scala would b…

how to access the list in different function

I have made a class in which there are 3 functions. def maxvalue def min value def getActionIn the def maxvalue function, I have made a list of actions. I want that list to be accessed in def getaction…

Replacing numpy array with max value [duplicate]

This question already has answers here:numpy max vs amax vs maximum(4 answers)Closed 2 years ago.I have an array, a = np.array([[0,9,8],[5,6,4]])how to replace the each array in axis 1 with the max val…

Finding the max and min in dictionary as tuples python

so given this dictionary im trying to find the max value and min value {Female :[18,36,35,49,19],Male :[23,22,6,36,46]}the output should be in tuples for example key: (min,max)Female: (18,49) Male: (6,…

Flask sqlalchemy relations across multiple files

Im new to Flask Sqlalchemy and I want to declare multiple models and relate them to each other, I followed the example in the documentation but I keep getting this error sqlalchemy.exc.InvalidRequestEr…

Parsing XML with Pykml

I have the following xml file I got from QGIS<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.…

Python Google App Engine Receiving a string in stead of JSON object

I am sending a HTTP POST request from android to a server using the script belowURI website = new URI("http://venkygcm.appspot.com");HttpClient client = new DefaultHttpClient();HttpPost reque…