penguins = sns.load_dataset("penguins")
sns.histplot(data=penguins, x="flipper_length_mm")
图形数据不显示,如图:
报错信息:
OptionError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_7568\482898880.py in----> 1 sns.histplot(data=penguins, x="flipper_length_mm") ~\anaconda3\lib\site-packages\seaborn\distributions.py in histplot(data, x, y, hue, weights, stat, bins, binwidth, binrange, discrete, cumulative, common_bins, common_norm, multiple, element, fill, shrink, kde, kde_kws, line_kws, thresh, pthresh, pmax, cbar, cbar_ax, cbar_kws, palette, hue_order, hue_norm, color, log_scale, legend, ax, **kwargs) 1460 if p.univariate: 1461 -> 1462 p.plot_univariate_histogram( 1463 multiple=multiple, 1464 element=element, ~\anaconda3\lib\site-packages\seaborn\distributions.py in plot_univariate_histogram(self, multiple, element, fill, common_norm, common_bins, shrink, kde, kde_kws, color, legend, line_kws, estimate_kws, **plot_kws) 426 427 # First pass through the data to compute the histograms --> 428 for sub_vars, sub_data in self.iter_data("hue", from_comp_data=True): 429 430 # Prepare the relevant data ~\anaconda3\lib\site-packages\seaborn\_core.py in iter_data(self, grouping_vars, reverse, from_comp_data) 981 982 if from_comp_data: --> 983 data = self.comp_data 984 else: 985 data = self.plot_data ~\anaconda3\lib\site-packages\seaborn\_core.py in comp_data(self) 1052 # Use the converter assigned to the axis to get a float representation 1053 # of the data, passing np.nan or pd.NA through (pd.NA becomes np.nan) -> 1054 with pd.option_context('mode.use_inf_as_null', True): 1055 orig = self.plot_data[var].dropna() 1056 comp_col = pd.Series(index=orig.index, dtype=float, name=var) ~\anaconda3\lib\site-packages\pandas\_config\config.py in __enter__(self) 439 440 def __enter__(self) -> None: --> 441 self.undo = [(pat, _get_option(pat, silent=True)) for pat, val in self.ops] 442 443 for pat, val in self.ops: ~\anaconda3\lib\site-packages\pandas\_config\config.py in (.0) 439 440 def __enter__(self) -> None: --> 441 self.undo = [(pat, _get_option(pat, silent=True)) for pat, val in self.ops] 442 443 for pat, val in self.ops: ~\anaconda3\lib\site-packages\pandas\_config\config.py in _get_option(pat, silent) 133 134 def _get_option(pat: str, silent: bool = False) -> Any: --> 135 key = _get_single_key(pat, silent) 136 137 # walk the nested dict ~\anaconda3\lib\site-packages\pandas\_config\config.py in _get_single_key(pat, silent) 119 if not silent: 120 _warn_if_deprecated(pat) --> 121 raise OptionError(f"No such keys(s): {repr(pat)}") 122 if len(keys) > 1: 123 raise OptionError("Pattern matched multiple keys") OptionError: "No such keys(s): 'mode.use_inf_as_null'"
解决方法:
我的pandas版本是2.0.2版本,但是mode.use_inf_as_null在这个版本不存在,需要回退到1.5.2版本才有这个模式。
查看当前模式:
import pandas as pd
# 显示当前 Pandas 版本
print(pd.__version__)
查询option下有哪些模式:
pd.describe_option()
在2.0.2下只有use_inf_as_na,没有use_inf_as_null。在下面链接中找到1.5.2版本中存在
mode.use_inf_as_null : boolean use_inf_as_null had been deprecated and will be removed in a future version. Use `use_inf_as_na` instead. [default: False] [currently: False] (Deprecated, use `mode.use_inf_as_na` instead.)
Options and settings — pandas 1.5.2 documentation (pydata.org)https://pandas.pydata.org/pandas-docs/version/1.5/user_guide/options.html回退pandas到1.5.2版本:
pip install pandas==1.5.2
问题解决。得到下图: