Skip to main content

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

Popular posts from this blog

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console...

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

The number of nodes and edges I calculated manually and by a method provided by networkx library dont match

I am trying to analyse a graph using networkx library in Python. I have implemented a function that returns the nodes and edges of that graph. After that I counted the number of nodes and edges by implementing the len() function for nodes and edges, which gave me 17 for both nodes and edges. However, when I used the method graph.number_of_nodes() of networkx library it gave me 53. My code: import pandas as pd import networkx as nx import matplotlib.pyplot as plt header_list = ["a","b","w"] E =pd.read_csv("aves-barn-swallow-contact-network.edges",sep=" ",header= None,names=header_list) # print(E.head()) # prints first few rows of the csv file G = nx.from_pandas_edgelist(E,"a","b",["w"]) nx.draw(G) plt.show() class GraphAnalyse: #finding nodes and edges def nodeEdge(self,Graph): nodes = Graph.nodes() edges = Graph.edges() ...