Python上的DatetimeIndex

时间:2019-04-08 23:32:02

标签: python pandas matplotlib

我正在创建一个数据可视化程序。运行我的代码时,出现以下错误:

TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Int64Index'

使用此代码:

import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
from mpl_finance import candlestick_ohlc
import matplotlib.dates as mdates
import pandas as pd
import pandas_datareader.data as web
style.use('ggplot')

df = pd.read_csv('Apple.csv', parse_dates=True, index_col=0)


df_ohlc = df['close'].resample('10d').ohlc()
df_volume = df['volume'].resample('10d').sum()

df_ohlc.reset_index()
df_ohlc['date'] = df_ohlc['date'].map(mdates.date2num)

ax1 = plt.subplot2grid((6,1), (0,0), rowspan=5, colspan=1)
ax2 = plt.subplot2grid((6,1), (5,0), rowspan=1, colspan=1, sharex=ax1)
ax1.xaxis_date()

candlestick_ohlc(ax1, df_ohlc.values, width=5, colorup='g')
ax2.fill_between(df_volume.index.map(mdates.date2num), df_volume.values, 0)
plt.show()

0 个答案:

没有答案