Data Analysis with Python - Data Analysis Example A

Tell us what’s happening:

corr = sales.corr() can’t convert str to float: ‘November’ in Data Analysis Example A

corr = sales.corr() #returns

ValueError: could not convert string to float: ‘November’

I’ve tied calling other methods but none work. I found a stack exchange post which suggests cat.codes to convert string to int.

What is the best way to remedy the error?

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:130.0) Gecko/20100101 Firefox/130.0

Challenge Information:

Data Analysis with Python - Data Analysis Example A

Can you please provide a bit more context, do you have a link to your google colab notebook?

Found this:
https://stackoverflow.com/questions/76533178/corr-results-in-valueerror-could-not-convert-string-to-float

since pandas version 2.0.0 now you need to add numeric_only=True param to avoid the issue

This worked for me, if you add numeric_only=True as an argument to .corr()

1 Like