I ran this code on Jupyter notebook. By default, it must have been able to take only the numerical values while calculating correlation. But it is not being able to do that and throwing the error as below:
df = sns.load_dataset("tips") df.head()
total_bill tip sex smoker day time size 0 16.99 1.01 Female No Sun Dinner 2 1 10.34 1.66 Male No Sun Dinner 3 2 21.01 3.50 Male No Sun Dinner 3 3 23.68 3.31 Male No Sun Dinner 2 4 24.59 3.61 Female No Sun Dinner 4
df.corr()
ValueError: could not convert string to float: 'No'
Expecting the correlation matrix of the numerical data but got error that it couldn't convert the string data.
Surely the data types for some data is not correct you will need to cast it to
floatto be able to make calculations. You can check the column data types by using:and you’ll see a column called
Dtypewhich will tell you what the data types are for each of the columns in your dataframe.With the format you have written in your question I don’t see the column organization for the the dataframe but you would need to do something similar to this:
and list all of them that you want to convert. Despite you see numbers, the interpreter is complaining that they are strings.