DataPrep 'plot(df)' 执行期间出错(JupyterLab)

Error during DataPrep 'plot(df)' executing (JupyterLab)

大家好! 尝试在 DataPrep 中执行 plot(df),但出现错误:

AttributeError: scipy.stats.stats is deprecated and has no attribute _power_div_lambda_names. Try looking in scipy.stats instead.

我已经尝试重新安装 dataprep、scipy、dask 等,但没有任何进展... 谁能帮帮我?

完整的错误输出如下:

AttributeError                            Traceback (most recent call last)
Input In [5], in <cell line: 1>()
----> 1 plot(df)

File ~\AppData\Roaming\Python\Python39\site-packages\dataprep\eda\distribution\__init__.py:101, in plot(df, col1, col2, col3, config, display, dtype, progress)
     98 cfg = Config.from_dict(display, config)
    100 with ProgressBar(minimum=1, disable=not progress):
--> 101     itmdt = compute(df, col1, col2, col3, cfg=cfg, dtype=dtype)
    103 to_render = render(itmdt, cfg)
    105 return Container(to_render, itmdt.visual_type, cfg)

File ~\AppData\Roaming\Python\Python39\site-packages\dataprep\eda\distribution\compute\__init__.py:72, in compute(df, col1, col2, col3, cfg, display, dtype)
     69 x, y, z = col1, col2, col3
     71 if not any([x, y, z]):
---> 72     return compute_overview(df, cfg, dtype)
     74 if sum(v is None for v in (x, y, z)) == 2:
     75     x = x or y or z

File ~\AppData\Roaming\Python\Python39\site-packages\dataprep\eda\distribution\compute\overview.py:57, in compute_overview(df, cfg, dtype)
     55 col_dtype = frame.get_eda_dtype(col)
     56 if isinstance(col_dtype, Continuous) and (cfg.hist.enable or cfg.insight.enable):
---> 57     data.append((col, col_dtype, _cont_calcs(frame.frame[col].dropna(), cfg)))
     58 elif isinstance(col_dtype, (Nominal, GeoGraphy, GeoPoint, SmallCardNum)) and (
     59     cfg.bar.enable or cfg.insight.enable
     60 ):
     61     srs = frame.get_col_as_str(col).dropna()

File ~\AppData\Roaming\Python\Python39\site-packages\dataprep\eda\distribution\compute\overview.py:125, in _cont_calcs(srs, cfg)
    122 data["hist"] = da.histogram(srs, bins=cfg.hist.bins, range=(srs.min(), srs.max()))
    124 if cfg.insight.enable:
--> 125     data["chisq"] = chisquare(data["hist"][0])
    126     data["norm"] = normaltest(data["hist"][0])
    127     data["skew"] = skewtest(data["hist"][0])

File ~\AppData\Roaming\Python\Python39\site-packages\dask\array\stats.py:136, in chisquare(f_obs, f_exp, ddof, axis)
    134 @derived_from(scipy.stats)
    135 def chisquare(f_obs, f_exp=None, ddof=0, axis=0):
--> 136     return power_divergence(f_obs, f_exp=f_exp, ddof=ddof, axis=axis, lambda_="pearson")

File ~\AppData\Roaming\Python\Python39\site-packages\dask\array\stats.py:144, in power_divergence(f_obs, f_exp, ddof, axis, lambda_)
    139 @derived_from(scipy.stats)
    140 def power_divergence(f_obs, f_exp=None, ddof=0, axis=0, lambda_=None):
    142     if isinstance(lambda_, str):
    143         # TODO: public api
--> 144         if lambda_ not in scipy.stats.stats._power_div_lambda_names:
    145             names = repr(list(scipy.stats.stats._power_div_lambda_names.keys()))[1:-1]
    146             raise ValueError(
    147                 f"invalid string for lambda_: {lambda_!r}. "
    148                 f"Valid strings are {names}"
    149             )

File ~\AppData\Roaming\Python\Python39\site-packages\scipy\stats\stats.py:54, in __getattr__(name)
     52 def __getattr__(name):
     53     if name not in __all__:
---> 54         raise AttributeError(
     55             "scipy.stats.stats is deprecated and has no attribute "
     56             f"{name}. Try looking in scipy.stats instead.")
     58     warnings.warn(f"Please use `{name}` from the `scipy.stats` namespace, "
     59                   "the `scipy.stats.stats` namespace is deprecated.",
     60                   category=DeprecationWarning, stacklevel=2)
     62     return getattr(_stats_py, name)

AttributeError: scipy.stats.stats is deprecated and has no attribute _power_div_lambda_names. Try looking in scipy.stats instead.

尝试更改您的导入行

已弃用:import scipy.stats.stats as stats

工作:import scipy.stats as stats

尝试在您的 python 或 conda 虚拟环境中安装 scipy 版本 1.7.1。
这对我有用。您只需在终端中输入以下代码即可安装:

pip install scipy==1.7.1

如果还是不能解决,那就试试另一个scipy版本1.5.4

pip install scipy==1.5.4