I am trying to follow the first steps with pandas.
After several successful steps, I was stuck in the following task: display data using OHLC columns.
I downloaded data for Apple from Google Finance and saved it in a * .csv file.
After a great search, I wrote the following code:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import datetime as dt
from matplotlib.finance import candlestick_ohlc
data = pd.read_csv("AAPL.csv")
fig, ax = plt.subplots()
ax.xaxis_date()
ax.xaxis.set_major_formatter(mdates.DateFormatter("%Y-%m-%d"))
plt.xlabel("Date")
plt.ylabel("Price")
plt.title("AAPL")
data['Date2'] = data['Date'].map(lambda d: mdates.date2num(dt.datetime.strptime(d, "%Y-%m-%d")))
candlestick_ohlc(ax, (data['Date2'], data['Open'], data['High'], data['Low'], data['Close']))
plt.show()
But it displays an empty graph. What is wrong with this code?
Thanks.
source
share