Skip to Content
Numerical Computing with Python
book

Numerical Computing with Python

by Pratap Dangeti, Allen Yu, Claire Chung, Aldrin Yim
December 2018
Beginner to intermediate
682 pages
18h 1m
English
Packt Publishing
Content preview from Numerical Computing with Python

How to do it...

  1. Load Amazon stock data and set the date as the index:
>>> amzn = pd.read_csv('data/amzn_stock.csv', index_col='Date',                      parse_dates=['Date'])>>> amzn.head()
  1. Create a Series by selecting only the closing price and then using the pct_change method to get the daily rate of return:
>>> amzn_daily_return = amzn.Close.pct_change()>>> amzn_daily_return.head()Date
2010-01-04         NaN
2010-01-05    0.005900
2010-01-06   -0.018116
2010-01-07   -0.017013
2010-01-08    0.027077
Name: Close, dtype: float64
  1. Drop the missing value and plot a histogram of the returns to visually inspect the distribution:
>>> amzn_daily_return = amzn_daily_return.dropna() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Numerical Computing with NumPy

Mastering Numerical Computing with NumPy

Umit Mert Cakmak, Tiago Antao, Mert Cuhadaroglu

Publisher Resources

ISBN: 9781789953633OtherOtherErrata Page