In [1]:
import quandl
import pandas as pd
quandl.ApiConfig.api_key = ""
# Retrieve Apple data
apple = quandl.get("WIKI/AAPL")
# Retrieve the MSFT data
ms = quandl.get("WIKI/MSFT")

In [3]:
%matplotlib inline
apple.head()


Out[3]:
Open High Low Close Volume Ex-Dividend Split Ratio Adj. Open Adj. High Adj. Low Adj. Close Adj. Volume
Date
1980-12-12 28.75 28.87 28.75 28.75 2093900.0 0.0 1.0 0.422706 0.424470 0.422706 0.422706 117258400.0
1980-12-15 27.38 27.38 27.25 27.25 785200.0 0.0 1.0 0.402563 0.402563 0.400652 0.400652 43971200.0
1980-12-16 25.37 25.37 25.25 25.25 472000.0 0.0 1.0 0.373010 0.373010 0.371246 0.371246 26432000.0
1980-12-17 25.87 26.00 25.87 25.87 385900.0 0.0 1.0 0.380362 0.382273 0.380362 0.380362 21610400.0
1980-12-18 26.63 26.75 26.63 26.63 327900.0 0.0 1.0 0.391536 0.393300 0.391536 0.391536 18362400.0

In [4]:
apple["Adj. Close"].plot()


Out[4]:
<matplotlib.axes._subplots.AxesSubplot at 0x116a652d0>

In [5]:
apple.index


Out[5]:
DatetimeIndex(['1980-12-12', '1980-12-15', '1980-12-16', '1980-12-17',
               '1980-12-18', '1980-12-19', '1980-12-22', '1980-12-23',
               '1980-12-24', '1980-12-26',
               ...
               '2018-03-14', '2018-03-15', '2018-03-16', '2018-03-19',
               '2018-03-20', '2018-03-21', '2018-03-22', '2018-03-23',
               '2018-03-26', '2018-03-27'],
              dtype='datetime64[ns]', name='Date', length=9400, freq=None)

In [6]:
apple["2018"]["Adj. Close"].plot()


Out[6]:
<matplotlib.axes._subplots.AxesSubplot at 0x118cb5990>

In [7]:
apple["2018-01-01":"2018-02-01"]["Adj. Close"].plot()


Out[7]:
<matplotlib.axes._subplots.AxesSubplot at 0x118bbfe50>

In [9]:
ms_price = ms[["Adj. Close"]]
ms_price.rename(columns={"Adj. Close":"MSFT"}, inplace=True)

In [10]:
apple_price = apple[["Adj. Close"]]
apple_price.rename(columns={"Adj. Close":"AAPL"}, inplace=True)

In [11]:
both_stocks = ms_price.join(apple_price, how="inner")
both_stocks.plot()


Out[11]:
<matplotlib.axes._subplots.AxesSubplot at 0x118fba810>

In [12]:
both_stocks.loc["2017"].plot()


Out[12]:
<matplotlib.axes._subplots.AxesSubplot at 0x119254710>

In [13]:
both_stocks["2017"].rolling(min_periods=10, window=60, center=False).mean().plot()


Out[13]:
<matplotlib.axes._subplots.AxesSubplot at 0x1193e3350>

In [14]:
both_stocks["2017"].rolling(min_periods=10, window=60, center=False).std().plot()


Out[14]:
<matplotlib.axes._subplots.AxesSubplot at 0x1194da310>

In [15]:



---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-15-3694d20cc2aa> in <module>
----> 1 apple.save()

~/Library/Caches/pypoetry/virtualenvs/pandas-sample-4shxcQQ7-py3.7/lib/python3.7/site-packages/pandas/core/generic.py in __getattr__(self, name)
   5272             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   5273                 return self[name]
-> 5274             return object.__getattribute__(self, name)
   5275 
   5276     def __setattr__(self, name: str, value) -> None:

AttributeError: 'DataFrame' object has no attribute 'save'

In [ ]: