4

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.

Elixir0101
  • 331
  • 1
  • 2
  • 15
  • Is there any other reason you want to avoid `corr` method? Because it is not deprecated in general, only the default value of its `numeric_only` argument. Using `df.corr(numeric_only = True)` (or False, depending on the needs) should get rid of the warning. – matszwecja Nov 03 '22 at 15:21
  • Okay thanks...I dont have any other reason for avoiding it other than it throwing errors in my code. – Elixir0101 Nov 03 '22 at 15:24
  • You should edit the post and add your code to get better help. – Esraa Abdelmaksoud Nov 03 '22 at 15:30
  • The problem doesn't lie on my code but on that one method - the corr method – Elixir0101 Nov 03 '22 at 15:33
  • However the comment by @matszwecja solved my problem..i would like to close this question. – Elixir0101 Nov 03 '22 at 15:34

2 Answers2

4

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.

3

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.

Elixir0101
  • 331
  • 1
  • 2
  • 15
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 06 '22 at 11:45