Extracting ASX data with pandas

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

My code looks like this

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 results in the 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 problem?

+3


source to share


2 answers


Thanks using.



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

      

+1


source


It's probably easier to use a package pandas_datareader

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

      

0


source







All Articles