Q:

Python - NaN values in df.corr

I am finishing a work and I am trying to check the correlation between some informations.
Basically I have the data from survivors from a incident and I want to know the correlation between other informations with their survavility.
So, I have the main df with all informations, then:
       #creating a df to list who not survived(0) and another df to list who survived(1)
 Input:     df_s0 = df.query("Survived == 0")
            df_s1 = df.query("Survived == 1")

 Input:     df_s0.corr()

A:

Based on correlation formula:

cor(a,b) = cov(a,b)/(stdev(a) * stdev(b))

If either a or b are all constant (zero variance) then correlation between those two are not defined (division by zero producing NaNs).
In your example, the Survived column of df_s0 is constant (all zeros) and hence correlation is undefined for this column with other columns.
If you want to figure out the relationship between a discrete variable (Survived) and the rest of your features, you can look at the box plots (to be able to compare different statistics like mean, IQR,...) of your features across different groups of Survived 0 and 1. If you want to go a step further you can use ANOVA to characterize the importance of your features based on their variance within and across different groups!

