我有一个股价收盘价的数据框:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn; seaborn.set()
from pandas_datareader import data
import pandas_datareader.data as web
from pandas.tseries.offsets import BDay
f = web.DataReader('^DJI', 'stooq')
CLOSE = f['Close']
CLOSE.plot(alpha= 0.5,style='-')
CLOSE.resample('BA').mean().plot(style=':')
CLOSE.asfreq(freq='BA').plot(style='--')
plt.legend(['input','resample','asfreq'],loc='upper left')
有了resample(),我得到了上一年的平均值。这可行。使用asfreq(),我尝试在年底获得结算值。这行不通。我在asfreq()行中收到以下错误:TypeError:没有要绘制的数字数据
f.info()显示close是非null的float64类型。
可能出什么事了?
索引未按等级排序:
f = f.sort_index(axis = 0)解决了它。