Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error when I try to find mean in pandas version 2.0.3

I try to find mean in pandas version 2.0.3 BUT this problem not in pandas version 0.23.3

df.mean()

I face the following error:
ValueError: could not convert string to float

to solution this problem I use:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

df.describe().mean()

What is the reason of this problem?

>Solution :

Ah. I see what happened here. Check the float values and ensure they don’t contain any commas or any other characters. You want to use the .Replace function to eliminate those extra characters.

edit **
there is also the to_numeric function.

What the error is saying is that the aggregate function isn’t able to work on the data because the data types don’t match. This can happen when the data has rows improperly represented, not counted as floats, or otherwise contain foreign characters.

The reason is works with "Describe" is being describe by default excludes nonnumeric and NaN rows.

DataFrame.mean(axis=0, skipna=True, numeric_only=False, **kwargs)
I’m wondering if the default behavior of the Pandas .mean() function is different from earlier versions. Try setting numeric_only to true.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading