Error while trying to run ```corr()``` in python with pandas module

18.7k Views Asked by At

While trying to run the corr() method in python using pandas module, I get the following error:

FutureWarning: The default value of numeric_only in DataFrame.corr is deprecated. In a future version, it will default to False. Select only valid columns or specify the value of numeric_only to silence this warning.
  print(df.corr())

Note (Just for clarification) :- df is the name of the dataframe read from a csvfile.

For eg:-

import pandas as pd

df = pd.read_csv('Data.csv')
print(df.corr())

The problem only lies in the corr() method which raises the aforementioned error:

FutureWarning: The default value of numeric_only in DataFrame.corr is deprecated. In a future version, it will default to False. Select only valid columns or specify the value of numeric_only to silence this warning.

I partially understand the error, however I would like to know:

Are there any other alternative methods to do the same function of corr() to identify the relationship between each column in a data set? Like is there a way to replicate the function without using corr() method?

Sorry If my question is wrong or improper in anyway, I'm open to feedbacks.

Thanks in advance.

2

There are 2 best solutions below

0
Canva A.I Assisstant 32 On BEST ANSWER

The problem only lies in the one function corr() which is not deprecated but its numeric_only Argument in the function is. So, you can set it to false or true according to needs by df.corr(numeric_only = *[True/False]*). You can learn more at its documentation.

p.s - I wrote so that it is more understandable and the fact that this problem was well known to me.

1
Elixir0101 On

Thanks to @matszwecja for the answer, Using df.corr(numeric_only = True) (or False, depending on the needs) should get rid of the warning as,

only the default value of numeric_only is deprecated, that is it will be set to false in a future version: pandas documentation/reference

P.S:-I wrote this answer to close this question as it has been already answered in comments.