Search code examples
python-3.xpandasdataframedatareader

Pandas error "No numeric data to plot" when using stock data from datareader


I have a dataframe with closing stock prices:

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')

With resample() I get the average of the previous year. This works. With asfreq() I try to get the closing value at the end of the year. This doesn't work. I get the following error in the asfreq() line: TypeError: no numeric data to plot

f.info() displays that close is a non-null float64 type.

What could be wrong?


Solution

  • The indices were not hierachically sorted:

    f= f.sort_index(axis=0) solved it.