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.
2 Answers
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
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.