I wrote basically two blocks of code exactly the same assign from the variables but I'm getting and error saying, "Setting an Array with a sequence". This is my code that didn't work:
east_fg_data = [["Heat", miaFG, miaWin], ["Knicks", nykFG, nykWin],
["Celitcs", bosFG, bosWin], ["76ers", phiFG, phiWin]]
east_fg_df = pd.DataFrame(east_fg_data, columns=['Teams', 'Field Goal Percentage', 'Wins'])
sns.lmplot(data = east_fg_df, x = 'Field Goal Percentage', y = 'Wins', hue = 'Teams',
fit_reg = True, ci = 95)
This is the code that did work:
west_ex_data = [["Nuggets", denNet, denPoints], ["Grizzlies", memNet, memPoints], ["Kings", sacNet, sacPoints],
["Suns", phxNet, phxPoints], ["Clippers", lacNet, lacPoints], ["Warriors", gswNet, gswPoints],
["Lakers", lalNet, lalPoints], ["Timberwolves", minNet, minPoints], ["Pelicans", nopNet, nopPoints],
["Thunder", okcNet, okcPoints]]
west_ex_df = pd.DataFrame(west_ex_data, columns=['Teams', 'Net Field Goal Percentage', 'Wins'])
sns.lmplot(data = west_ex_df, x = 'Net Field Goal Percentage', y = 'Wins', hue = 'Teams')
This is the error that code block 1 creates, the error did not appear for the second block:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/opt/anaconda3/lib/python3.9/site-packages/pandas/core/series.py in wrapper(self)
184 return converter(self.iloc[0])
--> 185 raise TypeError(f"cannot convert the series to {converter}")
186
TypeError: cannot convert the series to <class 'float'>
The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last)
/var/folders/n1/1bvy_hkj6d3chx2tpgxm3kt80000gn/T/ipykernel_50042/1816899590.py in <module>
7 east_df = pd.DataFrame(east_data, columns=['Teams', 'Net Field Goal Percentage', 'Wins'])
8
----> 9 sns.lmplot(data = east_df, x = 'Net Field Goal Percentage', y = 'Wins', hue = 'Teams')
/opt/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
/opt/anaconda3/lib/python3.9/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)
632 ax.autoscale_view(scaley=False)
633
--> 634 facets.map_dataframe(update_datalim, x=x, y=y)
635
636 # Draw the regression plot on each facet
/opt/anaconda3/lib/python3.9/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
/opt/anaconda3/lib/python3.9/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
/opt/anaconda3/lib/python3.9/site-packages/seaborn/regression.py in update_datalim(data, x, y, ax, **kws)
628
629 def update_datalim(data, x, y, ax, **kws):
--> 630 xys = np.asarray(data[[x, y]]).astype(float)
631 ax.update_datalim(xys, updatey=False)
632 ax.autoscale_view(scaley=False)
ValueError: setting an array element with a sequence.