使用来自数据读取器的股票数据时,熊猫错误“没有数字数据可绘制”

问题描述 投票:0回答:1

我有一个股价收盘价的数据框:

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类型。

可能出什么事了?

python-3.x pandas dataframe datareader
1个回答
0
投票

索引未按等级排序:

f = f.sort_index(axis = 0)解决了它。

© www.soinside.com 2019 - 2024. All rights reserved.