I use pandas to read a csv file to do some analysis. But the returned type is pandas.core.series.Series, which can not be converted to num using the command matplotlib.dates.date2num. Below is my code:
import pandas as pd import numpy as np from bokeh.plotting import figure, output_file, show import matplotlib.dates as mdates import time import matplotlib.pyplot as plt AAPL = pd.read_csv( "http://ichart.yahoo.com/table.csvs=AAPL&a=0&b=1&c=2009&d=0&e=1&f=2010", parse_dates=['Date'] ) x = AAPL['Date'] y = AAPL['Close'] print type(x) x = mdates.date2num(x) z4 = np.polyfit(x, y, 6) p4 = np.poly1d(z4) xx = np.linspace(x.min(), x.max(), 100) dd = mdates.num2date(xx) plt.plot(dd,p4(xx))
The command print type(x)
returns pandas.core.series.Series
. This one x = mdates.date2num(x)
returns the error as: AttributeError: 'numpy.datetime64' object has no attribute 'toordinal'.
Any one can shed a light on me for this issue?