stefmolin / Hands-On-Data-Analysis-with-Pandas-2nd-edition

Materials for following along with Hands-On Data Analysis with Pandas – Second Edition
https://www.amazon.com/Hands-Data-Analysis-Pandas-visualization/dp/1800563450
MIT License
584 stars 1.39k forks source link

Errors in running finacial_analysis.ipynb in chapter 7 #33

Closed lxlofpku closed 1 year ago

lxlofpku commented 1 year ago

Required attestation


Background information

1. Which OS are you using?

TODO: Provide your OS here – make sure to differentiate between Intel and M1 chip Macs.

Mac M2

2. Which Python version are you using?

TODO: Provide your Python version here.

Python 3.8

3. Are you using conda or venv?

TODO: Indicate whether you are using conda or venv.

conda


Commands run and their outputs

Please provide all of the commands you ran as well as the traceback:

Hi Stefanie:

Recently I installed the stock-analysis package following the instruction in chapter 7 (p. 395) of your book. That is, I installed it by running (in book_env environment):

  1. git clone git@github.com:stefmolin/stock-analysis.git
  2. pip3 install -r stock-analysis/requirements.txt
  3. pip3 install -e stock-analysis

All went through smoothly, indicating that the installation was successful.

However, as I run the finacial-analysis.ipynb notebook, I could not get the data. The problem is described in the attached screen shots. I have read through the trace back but cannot get a clue what is wrong.

Best regards, Li-Xin

The problem is displayed in the the screen shots displaced below. ``` TODO: paste commands and any traceback here ```

Screenshots

Optionally, include any screenshots that will help diagnose the issue. cap1 cap2

stefmolin commented 1 year ago

The stock_analysis library is using the pandas_datareader library to query the Yahoo! Finance API for the information. The API has recently changed, which is causing the issue since the pandas_datareader library doesn't yet know how to handle it. Upstream changes like this are expected, which is why I included all the datasets for this chapter in the data/ folder — use the note box right before "The Stock reader class" section in the book for a code snippet to read them in:

pd.read_csv('data/...', index_col='date', parse_dates=True)
lxlofpku commented 1 year ago

The stock_analysis library is using the pandas_datareader library to query the Yahoo! Finance API for the information. The API has recently changed, which is causing the issue since the pandas_datareader library doesn't yet know how to handle it. Upstream changes like this are expected, which is why I included all the datasets for this chapter in the data/ folder — use the note box right before "The Stock reader class" section in the book for a code snippet to read them in:

pd.read_csv('data/...', index_col='date', parse_dates=True)

Hi Stefanie, I understand it now. Thanks a lot!