seaborn lmplot logistic raises AttributeError: module 'pandas' has no attribute 'Panel'

377 Views Asked by At

I am using the code below that I took from the Seaborn documentation as it is. Running this code results in an error.

AttributeError: module 'pandas' has no attribute 'Panel'

I am wondering if there is a way around this problem without reverting to a previous version of Pandas. Can anyone help?

tips = sns.load_dataset("tips")
tips["big_tip"] = (tips.tip / tips.total_bill) > .15
sns.lmplot(x="total_bill", y="big_tip", data=tips,
           logistic=True, y_jitter=.03);

The version info as well as the complete error message are as follows:

pandas : 1.3.5 seaborn: '0.11.2'

--------------------------------------------------------------------------
AttributeError                           Traceback (most recent call last)
<ipython-input-4-2a96c34ef86c> in <module>
      2 tips["big_tip"] = (tips.tip / tips.total_bill) > .15
      3 sns.lmplot(x="total_bill", y="big_tip", data=tips,
----> 4            logistic=True, y_jitter=.03);

~/anaconda3/lib/python3.7/site-packages/seaborn/_decorators.py in inner_f(*args, **kwargs)
     44             )
     45         kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 46         return f(**kwargs)
     47     return inner_f
     48 

~/anaconda3/lib/python3.7/site-packages/seaborn/regression.py in lmplot(x, y, data, hue, col, row, palette, col_wrap, height, aspect, markers, sharex, sharey, hue_order, col_order, row_order, legend, legend_out, x_estimator, x_bins, x_ci, scatter, fit_reg, ci, n_boot, units, seed, order, logistic, lowess, robust, logx, x_partial, y_partial, truncate, x_jitter, y_jitter, scatter_kws, line_kws, facet_kws, size)
    643         scatter_kws=scatter_kws, line_kws=line_kws,
    644     )
--> 645     facets.map_dataframe(regplot, x=x, y=y, **regplot_kws)
    646     facets.set_axis_labels(x, y)
    647 

~/anaconda3/lib/python3.7/site-packages/seaborn/axisgrid.py in map_dataframe(self, func, *args, **kwargs)
    775 
    776             # Draw the plot
--> 777             self._facet_plot(func, ax, args, kwargs)
    778 
    779         # For axis labels, prefer to use positional args for backcompat

~/anaconda3/lib/python3.7/site-packages/seaborn/axisgrid.py in _facet_plot(self, func, ax, plot_args, plot_kwargs)
    804             plot_args = []
    805             plot_kwargs["ax"] = ax
--> 806         func(*plot_args, **plot_kwargs)
    807 
    808         # Sort out the supporting information

~/anaconda3/lib/python3.7/site-packages/seaborn/_decorators.py in inner_f(*args, **kwargs)
     44             )
     45         kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 46         return f(**kwargs)
     47     return inner_f
     48 

~/anaconda3/lib/python3.7/site-packages/seaborn/regression.py in regplot(x, y, data, x_estimator, x_bins, x_ci, scatter, fit_reg, ci, n_boot, units, seed, order, logistic, lowess, robust, logx, x_partial, y_partial, truncate, dropna, x_jitter, y_jitter, label, color, marker, scatter_kws, line_kws, ax)
    861     scatter_kws["marker"] = marker
    862     line_kws = {} if line_kws is None else copy.copy(line_kws)
--> 863     plotter.plot(ax, scatter_kws, line_kws)
    864     return ax
    865 

~/anaconda3/lib/python3.7/site-packages/seaborn/regression.py in plot(self, ax, scatter_kws, line_kws)
    368 
    369         if self.fit_reg:
--> 370             self.lineplot(ax, line_kws)
    371 
    372         # Label the axes

~/anaconda3/lib/python3.7/site-packages/seaborn/regression.py in lineplot(self, ax, kws)
    411         """Draw the model."""
    412         # Fit the regression model
--> 413         grid, yhat, err_bands = self.fit_regression(ax)
    414         edges = grid[0], grid[-1]
    415 

~/anaconda3/lib/python3.7/site-packages/seaborn/regression.py in fit_regression(self, ax, x_range, grid)
    209             from statsmodels.genmod.families import Binomial
    210             yhat, yhat_boots = self.fit_statsmodels(grid, GLM,
--> 211                                                     family=Binomial())
    212         elif self.lowess:
    213             ci = None

~/anaconda3/lib/python3.7/site-packages/seaborn/regression.py in fit_statsmodels(self, grid, model, **kwargs)
    279             return yhat
    280 
--> 281         yhat = reg_func(X, y)
    282         if self.ci is None:
    283             return yhat, None

~/anaconda3/lib/python3.7/site-packages/seaborn/regression.py in reg_func(_x, _y)
    273         def reg_func(_x, _y):
    274             try:
--> 275                 yhat = model(_y, _x, **kwargs).fit().predict(grid)
    276             except glm.PerfectSeparationError:
    277                 yhat = np.empty(len(grid))

~/anaconda3/lib/python3.7/site-packages/statsmodels/genmod/generalized_linear_model.py in __init__(self, endog, exog, family, offset, exposure, freq_weights, var_weights, missing, **kwargs)
    289                                   offset=offset, exposure=exposure,
    290                                   freq_weights=freq_weights,
--> 291                                   var_weights=var_weights, **kwargs)
    292         self._check_inputs(family, self.offset, self.exposure, self.endog,
    293                            self.freq_weights, self.var_weights)

~/anaconda3/lib/python3.7/site-packages/statsmodels/base/model.py in __init__(self, endog, exog, **kwargs)
    214 
    215     def __init__(self, endog, exog=None, **kwargs):
--> 216         super(LikelihoodModel, self).__init__(endog, exog, **kwargs)
    217         self.initialize()
    218 

~/anaconda3/lib/python3.7/site-packages/statsmodels/base/model.py in __init__(self, endog, exog, **kwargs)
     66         hasconst = kwargs.pop('hasconst', None)
     67         self.data = self._handle_data(endog, exog, missing, hasconst,
---> 68                                       **kwargs)
     69         self.k_constant = self.data.k_constant
     70         self.exog = self.data.exog

~/anaconda3/lib/python3.7/site-packages/statsmodels/base/model.py in _handle_data(self, endog, exog, missing, hasconst, **kwargs)
     89 
     90     def _handle_data(self, endog, exog, missing, hasconst, **kwargs):
---> 91         data = handle_data(endog, exog, missing, hasconst, **kwargs)
     92         # kwargs arrays could have changed, easier to just attach here
     93         for key in kwargs:

~/anaconda3/lib/python3.7/site-packages/statsmodels/base/data.py in handle_data(endog, exog, missing, hasconst, **kwargs)
    631         exog = np.asarray(exog)
    632 
--> 633     klass = handle_data_class_factory(endog, exog)
    634     return klass(endog, exog=exog, missing=missing, hasconst=hasconst,
    635                  **kwargs)

~/anaconda3/lib/python3.7/site-packages/statsmodels/base/data.py in handle_data_class_factory(endog, exog)
    611     if data_util._is_using_ndarray_type(endog, exog):
    612         klass = ModelData
--> 613     elif data_util._is_using_pandas(endog, exog):
    614         klass = PandasData
    615     elif data_util._is_using_patsy(endog, exog):

~/anaconda3/lib/python3.7/site-packages/statsmodels/tools/data.py in _is_using_pandas(endog, exog)
     99 
    100 def _is_using_pandas(endog, exog):
--> 101     from statsmodels.compat.pandas import data_klasses as klasses
    102     return (isinstance(endog, klasses) or isinstance(exog, klasses))
    103 

~/anaconda3/lib/python3.7/site-packages/statsmodels/compat/pandas.py in <module>
     21     except ImportError:
     22         from pandas.tseries import frequencies
---> 23     data_klasses = (pandas.Series, pandas.DataFrame, pandas.Panel)
     24 else:
     25     try:

~/anaconda3/lib/python3.7/site-packages/pandas/__init__.py in __getattr__(name)
    242         return _SparseArray
    243 
--> 244     raise AttributeError(f"module 'pandas' has no attribute '{name}'")
    245 
    246 

AttributeError: module 'pandas' has no attribute 'Panel'
1

There are 1 best solutions below

0
On

you are using the latest version of pandas library where Panal is removed from pandas version 0.25 and onward