pythonpandasfuture-warning

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


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.


Solution

  • 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.