'Seaborn pairplot not running only on a specific system

I have the following data with the name 'Salaries.csv'. It looks like the following:[The dataset has some columns like Index(['yearID', 'teamID', 'lgID', 'salary', 'num_feat'], dtype='object'). Please note that the column num_feat I have added to the DataFrame.

I want to do a Seaborn pairplot for team 'ATL' to plot scatter plots among all numeric features in the data frame.

I have the following code :

import seaborn as sns

var_set = [
    "yearID",
    "teamID",
    "lgID",
    "playerID",
    "salary"
]

head_set = []
head_set.extend(var_set)
head_set.append("num_feat")

df = pd.read_csv('Salaries.csv',index_col='playerID', header=None, names=head_set)

df['num_feat'] = 100 * np.random.random_sample(df.shape[0]). #Adding column num_feat

df_copy = df
cols_with_team_ATL = df_copy.loc[df_copy.teamID=="ATL", ]

# Create the default pairplot
pairplot_fig = sns.pairplot(cols_with_team_ATL, vars=['yearID', 'salary', 'num_feat'])
plt.subplots_adjust(top=0.9)
pairplot_fig.fig.suptitle("Scatter plots among all numeric features in the data frame for teamID = ATL", fontsize=18, alpha=0.9, weight='bold')
plt.show()

The same code runs perfectly on my friend's system but not on mine. It shows the following error in my system :

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/var/folders/ch/6r9p7n0j3xg1l79lz1zdkvsh0000gq/T/ipykernel_97373/3735184261.py in <module>
     25 # Create the default pairplot
     26 print(df.columns)
---> 27 pairplot_fig = sns.pairplot(cols_with_team_ATL, vars=['yearID', 'salary', 'num_feat'])
     28 plt.subplots_adjust(top=0.9)
     29 pairplot_fig.fig.suptitle("Scatter plots among all numeric features in the data frame for teamID = ATL", fontsize=18, alpha=0.9, weight='bold')

~/USC/anaconda3/lib/python3.9/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 

~/USC/anaconda3/lib/python3.9/site-packages/seaborn/axisgrid.py in pairplot(data, hue, hue_order, palette, vars, x_vars, y_vars, kind, diag_kind, markers, height, aspect, corner, dropna, plot_kws, diag_kws, grid_kws, size)
   2124     diag_kws.setdefault("legend", False)
   2125     if diag_kind == "hist":
-> 2126         grid.map_diag(histplot, **diag_kws)
   2127     elif diag_kind == "kde":
   2128         diag_kws.setdefault("fill", True)

~/USC/anaconda3/lib/python3.9/site-packages/seaborn/axisgrid.py in map_diag(self, func, **kwargs)
   1476             plot_kwargs.setdefault("hue_order", self._hue_order)
   1477             plot_kwargs.setdefault("palette", self._orig_palette)
-> 1478             func(x=vector, **plot_kwargs)
   1479             ax.legend_ = None
   1480 

~/USC/anaconda3/lib/python3.9/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,

~/USC/anaconda3/lib/python3.9/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

~/USC/anaconda3/lib/python3.9/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

~/USC/anaconda3/lib/python3.9/site-packages/seaborn/_core.py in comp_data(self)
   1055                     orig = self.plot_data[var].dropna()
   1056                 comp_col = pd.Series(index=orig.index, dtype=float, name=var)
-> 1057                 comp_col.loc[orig.index] = pd.to_numeric(axis.convert_units(orig))
   1058 
   1059                 if axis.get_scale() == "log":

~/USC/anaconda3/lib/python3.9/site-packages/pandas/core/indexing.py in __setitem__(self, key, value)
    721 
    722         iloc = self if self.name == "iloc" else self.obj.iloc
--> 723         iloc._setitem_with_indexer(indexer, value, self.name)
    724 
    725     def _validate_key(self, key, axis: int):

~/USC/anaconda3/lib/python3.9/site-packages/pandas/core/indexing.py in _setitem_with_indexer(self, indexer, value, name)
   1730             self._setitem_with_indexer_split_path(indexer, value, name)
   1731         else:
-> 1732             self._setitem_single_block(indexer, value, name)
   1733 
   1734     def _setitem_with_indexer_split_path(self, indexer, value, name: str):

~/USC/anaconda3/lib/python3.9/site-packages/pandas/core/indexing.py in _setitem_single_block(self, indexer, value, name)
   1966 
   1967         # actually do the set
-> 1968         self.obj._mgr = self.obj._mgr.setitem(indexer=indexer, value=value)
   1969         self.obj._maybe_update_cacher(clear=True)
   1970 

~/USC/anaconda3/lib/python3.9/site-packages/pandas/core/internals/managers.py in setitem(self, indexer, value)
    353 
    354     def setitem(self: T, indexer, value) -> T:
--> 355         return self.apply("setitem", indexer=indexer, value=value)
    356 
    357     def putmask(self, mask, new, align: bool = True):

~/USC/anaconda3/lib/python3.9/site-packages/pandas/core/internals/managers.py in apply(self, f, align_keys, ignore_failures, **kwargs)
    325                     applied = b.apply(f, **kwargs)
    326                 else:
--> 327                     applied = getattr(b, f)(**kwargs)
    328             except (TypeError, NotImplementedError):
    329                 if not ignore_failures:

~/USC/anaconda3/lib/python3.9/site-packages/pandas/core/internals/blocks.py in setitem(self, indexer, value)
    941 
    942         # length checking
--> 943         check_setitem_lengths(indexer, value, values)
    944         exact_match = is_exact_shape_match(values, arr_value)
    945 

~/USC/anaconda3/lib/python3.9/site-packages/pandas/core/indexers.py in check_setitem_lengths(indexer, value, values)
    174                     and len(indexer[indexer]) == len(value)
    175                 ):
--> 176                     raise ValueError(
    177                         "cannot set using a list-like indexer "
    178                         "with a different length than the value"

ValueError: cannot set using a list-like indexer with a different length than the value

Why is it not running particularly on my system? Is there any problem with the python version or Jupyter Notebook?

Please help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source