0
$\begingroup$

#

when I am trying to run sns.heatmap(df.corr(),annot=True) this code in my jupyter notebook. this error is occuring. I cannot understand this problem. please help me.

$\endgroup$

2 Answers 2

0
$\begingroup$

For df.corr() you would have to pass float/integer instead of string. You can check this answer on stack overflow as well - https://stackoverflow.com/questions/51241575/calculate-correlation-between-columns-of-strings.

To convert the strings to the integers/floats you can use feature extraction techniques used in NLP like CountVectorizer, TfidifVectorizer, Word Embedding. You can refer this documentation - https://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.CountVectorizer.html

$\endgroup$
0
$\begingroup$

Use this:

my_df = df.select_dtypes(exclude=[object])

This will select only the integer and float columns from your dataframe. After this you can use:

my_df.corr()

Hope it will work.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.