【问题标题】:Statsmodels: requires arrays without NaN or Infs - but test shows there are no NaNs or InfsStatsmodels:需要没有 NaN 或 Infs 的数组 - 但测试显示没有 NaN 或 Infs
【发布时间】:2018-09-15 21:10:36
【问题描述】:

我正在尝试从 statsmodels 的 adfuller 模块运行 ADF 测试。它给了我一个错误:

ValueError: array must not contain infs or NaNs

通过另一个问题,我可以替换我的 NaN (NaN in data frame: when first observation of time series is NaN, frontfill with first available, otherwise carry over last / previous observation.

虽然我检查了 NaN 和 inf:

df[pd.isnull(df).any(axis=1)]
np.isinf(df).any()
np.isnan(df).any()

pandas 语句给我“无结果”,numpy 语句都给我“假”,我的函数仍然告诉我同样的错误。

有错误吗?

ValueError: array must not contain infs or NaNs during Biclustering

【问题讨论】:

  • df.replace(np.inf,np.nan).isnull().any()
  • 显示回溯或至少显示异常发生位置的结尾。没有足够的信息来做出“疯狂的猜测”。 MWE 会更好。

标签: pandas missing-data statsmodels


【解决方案1】:

我现在已经解决了:

 x = pd.DataFrame(x.replace([np.inf, -np.inf], np.nan))
 x = x.fillna(method='ffill')
 x = x.fillna(method='bfill')
 x = x.iloc[:, 0]

这给了我一个没有任何 nan 的 x 系列。问题是从系列切换到数据框并返回系列

【讨论】:

    猜你喜欢
    • 2010-12-21
    • 2019-10-31
    • 2016-01-31
    • 2021-07-07
    • 2017-05-04
    • 2021-07-20
    • 2016-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多