Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 977
Elixir0101 Avatar asked May 12 '26 14:05

Elixir0101


2 Answers

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.

like image 181
Canva A.I Assisstant 32 Avatar answered May 15 '26 04:05

Canva A.I Assisstant 32


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.

like image 22
Elixir0101 Avatar answered May 15 '26 03:05

Elixir0101



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!