Error on Seaborn lmplot when passing dataframe data due to dtype('O') error, except I've replaced all object dtypes [duplicate]
Background
I have a dataframe imported from an excel doc. Each column is an experiment variable and every row is an entry. The dataframe is 242x18.
I am attempting to plot 1x3 lmplot, plotting two Float64 dtypes against one another. Data shown below for context: Data in question dtypes of data
Here are the dtypes of the full dataframe: dtypes of full dataframe
Note that it was read in as: dtypes of full dataframe prior to conversion
Where I then used:
df = df_forging.convert_dtypes()
The Error
The function I'm using is exactly:
g = sns.lmplot(data = df,y='Peak Tensile Force (N)',x='Elliptical Area (mm^2)')
Which returns the following:
---------------------------------------------------------------------------
UFuncTypeError Traceback (most recent call last)
>! \~\\AppData\\Local\\Temp\\ipykernel_27312\\4132946937.py in \<module\>
1 # Isolate to one weld population
2 g = sns.lmplot(data=df_forging,
3 y='Peak Tensile Force (N)',
4 x='Elliptical Area (mm^2)'
5 # hue='Weld Population',
C:\\ProgramData\\Anaconda3\\lib\\site-packages\\seaborn\\regression.py in lmplot(data, x, y, 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)
633 scatter_kws=scatter_kws, line_kws=line_kws,
634 )
635 facets.map_dataframe(regplot, x=x, y=y, \*\*regplot_kws)
636 facets.set_axis_labels(x, y)
637
C:\\ProgramData\\Anaconda3\\lib\\site-packages\\seaborn\\axisgrid.py in map_dataframe(self, func, \*args, \*\*kwargs)
817
818 # Draw the plot
819 self.\_facet_plot(func, ax, args, kwargs)
820
821 # For axis labels, prefer to use positional args for backcompat
C:\\ProgramData\\Anaconda3\\lib\\site-packages\\seaborn\\axisgrid.py in \_facet_plot(self, func, ax, plot_args, plot_kwargs)
846 plot_args = \[\]
847 plot_kwargs\["ax"\] = ax
848 func(\*plot_args, \*\*plot_kwargs)
849
850 # Sort out the supporting information
C:\\ProgramData\\Anaconda3\\lib\\site-packages\\seaborn\\regression.py in regplot(data, x, y, 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)
757 scatter_kws\["marker"\] = marker
758 line_kws = {} if line_kws is None else copy.copy(line_kws)
759 plotter.plot(ax, scatter_kws, line_kws)
760 return ax
761
C:\\ProgramData\\Anaconda3\\lib\\site-packages\\seaborn\\regression.py in plot(self, ax, scatter_kws, line_kws)
366
367 if self.fit_reg:
368 self.lineplot(ax, line_kws)
369
370 # Label the axes
C:\\ProgramData\\Anaconda3\\lib\\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
C:\\ProgramData\\Anaconda3\\lib\\site-packages\\seaborn\\regression.py in fit_regression(self, ax, x_range, grid)
217 yhat, yhat_boots = self.fit_logx(grid)
218 else:
219 yhat, yhat_boots = self.fit_fast(grid)
220
221 # Compute the confidence interval at each grid point
C:\\ProgramData\\Anaconda3\\lib\\site-packages\\seaborn\\regression.py in fit_fast(self, grid)
234 X, y = np.c\_\[np.ones(len(self.x)), self.x\], self.y
235 grid = np.c\_\[np.ones(len(grid)), grid\]
236 yhat = grid.dot(reg_func(X, y))
237 if self.ci is None:
238 return yhat, None
C:\\ProgramData\\Anaconda3\\lib\\site-packages\\seaborn\\regression.py in reg_func(\_x, \_y)
230 """Low-level regression and prediction using linear algebra."""
231 def reg_func(\_x, \_y):
232 return np.linalg.pinv(\_x).dot(_y)
233
234 X, y = np.c_\[np.ones(len(self.x)), self.x\], self.y
C:\\ProgramData\\Anaconda3\\lib\\site-packages\\numpy\\core\\overrides.py in pinv(\*args, \*\*kwargs)
C:\\ProgramData\\Anaconda3\\lib\\site-packages\\numpy\\linalg\\linalg.py in pinv(a, rcond, hermitian)
1996 return wrap(res)
1997 a = a.conjugate()
1998 u, s, vt = svd(a, full_matrices=False, hermitian=hermitian)
1999
2000 # discard small singular values
C:\\ProgramData\\Anaconda3\\lib\\site-packages\\numpy\\core\\overrides.py in svd(\*args, \*\*kwargs)
C:\\ProgramData\\Anaconda3\\lib\\site-packages\\numpy\\linalg\\linalg.py in svd(a, full_matrices, compute_uv, hermitian)
1655
1656 signature = 'D-\>DdD' if isComplexType(t) else 'd-\>ddd'
1657 u, s, vh = gufunc(a, signature=signature, extobj=extobj)
1658 u = u.astype(result_t, copy=False)
1659 s = s.astype(\_realType(result_t), copy=False)
UFuncTypeError: Cannot cast ufunc 'svd_n_s' input from dtype('O') to dtype('float64') with casting rule 'same_kind'
What I've tried
As mentioned above, I fixed all the dtypes to better fit the contained data. I have used the same dataset with seaborn.scatterplot, which worked without error.
I think the issue is that it think it's seeing an dtype('O')
, but I don't see how that can be.
source https://stackoverflow.com/questions/75546110/error-on-seaborn-lmplot-when-passing-dataframe-data-due-to-dtypeo-error-exc
Comments
Post a Comment