Furqan Hashim
Furqan Hashim

Reputation: 1318

Extracting ASX data using pandas

I am trying to extract stock market data from yahoo finance following is the link https://au.finance.yahoo.com/quote/ABP.AX/history?p=ABP.AX

My code is as follows

import pandas as pd
dfs = pd.read_html('https://au.finance.yahoo.com/quote/ABP.AX/history?p=ABP.AX')       
print(dfs)

The above code leads to following error

Traceback (most recent call last):
  File "/home/furqan/Desktop/Data/Fundamental Analysis/get_data/ax_data.py", line 5, in <module>
    dfs = pd.read_html('https://au.finance.yahoo.com/quote/ABP.AX/history?p=ABP.AX')
  File "/usr/local/lib/python3.5/dist-packages/pandas/io/html.py", line 874, in read_html
    parse_dates, tupleize_cols, thousands, attrs, encoding)
  File "/usr/local/lib/python3.5/dist-packages/pandas/io/html.py", line 747, in _parse
    thousands=thousands))
  File "/usr/local/lib/python3.5/dist-packages/pandas/io/html.py", line 628, in _data_to_frame
    _expand_elements(body)
  File "/usr/local/lib/python3.5/dist-packages/pandas/io/html.py", line 611, in _expand_elements
    body[ind] += empty * (lens_max - length)
TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U47') dtype('<U47') dtype('<U47')

How can I solve this issue?

Upvotes: 2

Views: 3839

Answers (2)

Furqan Hashim
Furqan Hashim

Reputation: 1318

Thanks done using.

import fix_yahoo_finance as yf
data = yf.download("SPY", start="2017-01-01", end="2017-04-30")

Upvotes: 1

Corley Brigman
Corley Brigman

Reputation: 12401

It's probably easier to use the pandas_datareader package for this:

pip3 install pandas_datareader

from pandas_datareader import yahoo
In [13]: yahoo.quotes.YahooQuotesReader('ABP.AX').read()
Out[13]: 
          PE change_pct  last  short_ratio    time
ABP.AX  5.65     -1.94%  3.04          0.0  4:10pm

Upvotes: 0

Related Questions