上QQ阅读APP看书,第一时间看更新
How to do it...
The following code plots the time series chart of the Google Stock Price:
- Load the Google Stock Price file (date and price) into x, y coordinates:
stock = pd.read_csv('GOOG.csv', header=None, delimiter=',')
- Add column names:
stock.columns = ['date','price']
- Convert the pandas DataFrame into a time series:
stock['date'] = pd.to_datetime(stock['date'], format='%d-%m-%Y')
- Set the date as the index for the pandas DataFrame:
indexed_stock = stock.set_index('date')
ts = indexed_stock['price']
- Plot the graph:
plt.plot(ts)
- Display the graph on the screen:
plt.show()