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:
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.