As @Karl D. mentioned, if the values in a column are the same, then there's no variance in that column, i.e. the values are constant and the correlation between a random variable and a constant is undefined. Another way to look at it is if a column with zero variance is plotted in a graph, it will be a horizontal line, which means it doesn't "move together" with any other plot on the same graph.
If we're interested in a correlation matrix, then one way is to simply drop the columns where correlation is not defined:
corr = df.corr()
corr_notna = ~corr.isna().all()
corr = corr.loc[corr_notna, corr_notna]
# or as a one-liner
corr = df.corr().dropna(how='all', axis=1).dropna(how='all')
The difference between a constant column and another random variable will have correlation = 1 or -1. For example,
df = pd.DataFrame({'A': [1]*5, 'B': [*[1]*4, 0]})
df.corr()
df.corr()
A B
A NaN NaN
B NaN 1.0
df['B-A'] = df['B'] - df['A']
df[['B', 'B-A']].corr()
B B-A
B 1.0 1.0
B-A 1.0 1.0
Another way to get NaN is if there are not enough data to compute correlation especially if min_periods=
was set to a number. An example:
df = pd.DataFrame({'A': [*range(9), float('nan')], 'B': range(10)})
df.corr(min_periods=10)
A B
A NaN NaN
B NaN 1.0