title: MissingDataError: exog contains inf or nans when use adfuller
body: <p><a href="https://i.stack.imgur.com/Mzv8k.png" rel="nofollow noreferrer">enter image description here</a><br />
  code(part):
  data = data.iloc[24:].fillna(method = 'ffill')</p>
  <pre><code>ts=data['pm2.5']
  
  ts_log = np.log(ts)
  
  print(np.isnan(ts_log).sum())[enter image description here][1]
  
  from statsmodels.tsa.seasonal import seasonal_decompose
  decomposition = seasonal_decompose(ts_log)
  trend = decomposition.trend
  seasonal = decomposition.seasonal
  residual = decomposition.resid
  
      bug:
      ValueError                                Traceback (most recent call last)
      &lt;ipython-input-25-0d6bd884b128&gt; in &lt;module&gt;
        
        1 from statsmodels.tsa.seasonal import seasonal_decompose
  ----&gt; 2 decomposition = seasonal_decompose(ts_log)
        3 
        4 trend = decomposition.trend
  
  g:\python\python37\lib\site-packages\pandas\util\_decorators.py in wrapper(*args, **kwargs)
      212                 else:
      213                     kwargs[new_arg_name] = new_arg_value
  --&gt; 214             return func(*args, **kwargs)
      215 
      216         return cast(F, wrapper)
  </code></pre>
  <p>g:\python\python37\lib\site-packages\statsmodels\tsa\seasonal.py in seasonal_decompose(x, model,      filt, period, two_sided, extrapolate_trend)
  129
  130     if not np.all(np.isfinite(x)):
  131         raise ValueError(&quot;This function does not handle missing values&quot;)
  132     if model.startswith('m'):
  133         if np.any(x &lt;= 0):</p>
  <p>ValueError: This function does not handle missing values</p>
  <pre><code>  [1]: https://i.stack.imgur.com/X6nNW.pngenter image description here
  </code></pre>
  <p><a href="https://i.stack.imgur.com/3veYu.png" rel="nofollow noreferrer">enter image description here</a></p>
  <pre><code>FULL CODE
  #!/usr/bin/env python
  # coding: utf-8
  
  # In[1]:
  
  
  import pandas as pd
  import numpy as np
  import matplotlib.pyplot as plt
  get_ipython().run_line_magic('matplotlib', 'inline')
  # pd.plotting.register_matplotlib_converters()
  
  
  data = pd.read_csv('E:/硕士开题/数据/美国驻北京大使馆10-14/PRSA_data_2010.1.1-2014.12.31.csv')
  pd.set_option('display.max_columns', None) #显示所有列
  pd.set_option('expand_frame_repr', False) #数据超过总宽度后，是否折叠显示
  
  
  # In[2]:
  
  
  data = data.iloc[24:].fillna(method = 'ffill')
  
  import datetime
  data['Time'] = data.apply(lambda x: datetime.datetime(year=x['year'],month =x['month'],day = x['day'],hour = x['hour']),axis = 1) #把年月日小时合并为一列
  
  data.drop(columns=['No', 'year', 'month', 'day', 'hour'], inplace=True)
  data = data.set_index('Time')
  data.head()
  
  
  # In[3]:
  
  
  # data.to_csv('E:/aaaa.csv')
  plt.figure(figsize=(24,10))
  plt.plot(data['pm2.5'])
  
  
  plt.show()
  
  
  # In[4]:
  
  
  ts=data['pm2.5']
  
  ts.head()
  _index = ts.index
  _index
  
  
  # In[5]:
  
  
  #归一化
  import sklearn.preprocessing as preprocessing
  s1 = preprocessing.StandardScaler()
  s2 = preprocessing.StandardScaler()
  
  ts_array = ts.values
  ts = ts_array.reshape(len(ts),1)
  ts = s2.fit_transform(ts)
  
  
  ts = ts.reshape(len(ts))
  
  ts = pd.Series(ts,index=_index)
  
  ts = pd.DataFrame(ts)
  
  ts.head()
  
  # pd.DataFrame(ts).columns.values.tolist()
  
  
  # In[6]:
  
  
  #检查平稳性
  from statsmodels.tsa.stattools import adfuller
  def test_stationarity(timeseries):
      
      #Determing rolling statistics
      rolmean = timeseries.rolling(window=12).mean()
      rolstd = timeseries.rolling(window=12).std()
  
      #Plot rolling statistics:
      orig = plt.plot(timeseries, color='blue',label='Original')
      mean = plt.plot(rolmean, color='red', label='Rolling Mean')
      std = plt.plot(rolstd, color='black', label = 'Rolling Std')
      plt.legend(loc='best')
      plt.title('Rolling Mean &amp; Standard Deviation')
      plt.show(block=False)
      
      #Perform Dickey-Fuller test:
      print('Results of Dickey-Fuller Test:')
      dftest = adfuller(timeseries, autolag='AIC')
      dfoutput = pd.Series(dftest[0:4], index=['Test Statistic','p-value','#Lags Used','Number of Observations Used'])
      for key,value in dftest[4].items():
          dfoutput['Critical Value (%s)'%key] = value
      print(dfoutput)
  
  
  # In[7]:
  
  
  test_stationarity(ts)
  
  
  # In[18]:
  
  
  #取对数查看趋势
  ts_log = np.log(ts)
  ts_log.dropna(inplace = True)
  print(np.isnan(ts_log).sum())
  # test_stationarity(ts_log)
  plt.plot(ts_log)
  ts_log.info()
  
  
  # In[9]:
  
  
  #12项指数加权移动平均
  expwighted_avg = pd.DataFrame.ewm(ts_log,halflife = 12).mean()
  plt.plot(ts_log)
  plt.plot(expwighted_avg,color ='red')
  
  
  # In[10]:
  
  
  ts_log_ewma_diff = ts_log - expwighted_avg #把移动平均从原始时间序列中减去
  
  test_stationarity(ts_log_ewma_diff) #再检查平稳性
  
  
  # In[11]:
  
  
  #消除季节性和趋势
  #使用一次偏移进行差异化
  ts_log_diff = ts_log - ts_log.shift()
  plt.plot(ts_log_diff)
  
  
  # In[12]:
  
  
  ts_log_diff.dropna(inplace = True)
  
  test_stationarity(ts_log_diff)
  
  
  # In[13]:
  
  
  #分离趋势季节误差
  from statsmodels.tsa.seasonal import seasonal_decompose
  decomposition = seasonal_decompose(ts_log,period = 1)
  
  trend = decomposition.trend
  seasonal = decomposition.seasonal
  residual = decomposition.resid
  
  plt.subplot(411)
  plt.plot(ts_log, label='Original')
  plt.legend(loc='best')
  plt.subplot(412)
  plt.plot(trend, label='Trend')
  plt.legend(loc='best')
  plt.subplot(413)
  plt.plot(seasonal,label='Seasonality')
  plt.legend(loc='best')
  plt.subplot(414)
  plt.plot(residual, label='Residuals')
  plt.legend(loc='best')
  plt.tight_layout()
  
  
  # In[14]:
  
  
  #差分后 绘制TS的ACF和PACF图
  #ACF and PACF plots:
  from statsmodels.tsa.stattools import acf, pacf
  
  lag_acf = acf(ts_log_diff, nlags=20)
  lag_pacf = pacf(ts_log_diff, nlags=20, method='ols')
  
  
  # In[15]:
  
  
  #Plot ACF: 
  plt.subplot(121) 
  plt.plot(lag_acf)
  plt.axhline(y=0,linestyle='--',color='gray')
  plt.axhline(y=-1.96/np.sqrt(len(ts_log_diff)),linestyle='--',color='gray')
  plt.axhline(y=1.96/np.sqrt(len(ts_log_diff)),linestyle='--',color='gray')
  plt.title('Autocorrelation Function')
  
  #Plot PACF:
  plt.subplot(122)
  plt.plot(lag_pacf)
  plt.axhline(y=0,linestyle='--',color='gray')
  plt.axhline(y=-1.96/np.sqrt(len(ts_log_diff)),linestyle='--',color='gray')
  plt.axhline(y=1.96/np.sqrt(len(ts_log_diff)),linestyle='--',color='gray')
  plt.title('Partial Autocorrelation Function')
  plt.tight_layout()
  
  
  # In[16]:
  
  
  # ts_log.reset_index(drop=True)
  print(np.isnan(ts_log).sum())
  
  
  # In[17]:
  
  
  from statsmodels.tsa.arima_model import ARIMA
  
  model = ARIMA(ts_log, order=(2, 1, 2))  
  results_ARIMA = model.fit(disp=-1)  
  plt.plot(ts_log_diff)
  plt.plot(results_ARIMA.fittedvalues, color='red')
  plt.title('RSS: %.4f'% sum((results_ARIMA.fittedvalues-ts_log_diff)**2))
  
  
  # In[ ]:
  
  
  # #恢复到原始比例
  # predictions_ARIMA_diff = pd.Series(results_ARIMA.fittedvalues, copy=True)
  # predictions_ARIMA_diff.head()
  
  # predictions_ARIMA_diff_cumsum = predictions_ARIMA_diff.cumsum()
  # predictions_ARIMA_diff_cumsum.head()
  
  # predictions_ARIMA_log = pd.Series(ts_log.iloc[0], index=ts_log.index)
  # predictions_ARIMA_log = predictions_ARIMA_log.add(predictions_ARIMA_diff_cumsum,fill_value=0)
  # predictions_ARIMA_log.head()
  
  
  # predictions_ARIMA = np.exp(predictions_ARIMA_log)
  # plt.plot(ts)
  # plt.plot(predictions_ARIMA)
  # plt.title('RMSE: %.4f'% np.sqrt(sum((predictions_ARIMA - ts)**2)/len(ts)))
  
  
  # In[ ]:
  
  
  
  
  
  # In[ ]:
  </code></pre>
  <p>IF anyone can help me,i would be gratful.the data i can transport to you</p>