Python Stock Analysis Series - Data collation and draw .p2
Welcome to Part 2 Python for Finance tutorial series. In this tutorial, we will use our further decomposition of some of the basic data of the stock data manipulation and visualization. We start code to be used (in the previous tutorial has been introduced) are:
import datetime as dt import matplotlib.pyplot as plt from matplotlib import style import pandas as pd import pandas_datareader.data as web style.use('ggplot') start = dt.datetime(2000,1,1) end = dt.datetime(2016,12,31) df = web.DataReader('TSLA', 'yahoo', start, end)
What can we do with these DataFrame? First, we can easily save them for a variety of data types. One option is to csv:
df.to_csv('TSLA.csv')
We can also read data from a CSV file to DataFrame instead of reading data from Yahoo Finance API to DataFrame in:
df = pd.read_csv('tsla.csv', parse_dates=True, index_col=0)
Now, with instructions to draw:
df.plot() plt.show()
Cool, except the only thing we can really see it is volume, because it is much larger than the stock price. How can we map out what we are interested in?
df['Adj Close'].plot() plt.show()
As you can see, you can refer to a particular column in DataFrame, for example: df [ 'Adj Close'], but you can also a plurality of reference, as follows:
df[['High','Low']]
Next tutorial, we will introduce some of the basic operations of these data, as well as some of the more basic visualization.