DataFrame correlation produces NaN although its values are all integers

前端 未结 1 1276
日久生厌
日久生厌 2020-12-17 20:40

I have a dataframe df:

df   = pandas.DataFrame(pd.read_csv(loggerfile, header = 2))

values = df.as_matrix()

df2 = pd.DataFrame.from_records(va         


        
相关标签:
1条回答
  • 2020-12-17 21:22

    Those columns do not change in value right now, yes

    As, Joris points out you would expected NaN if the values do not vary. To see why take a look at correlation formula:

    cor(i,j) = cov(i,j)/[stdev(i)*stdev(j)]
    

    If the values of the ith or jth variable do not vary, then the respective standard deviation will be zero and so will the denominator of the fraction. Thus, the correlation will be NaN.

    0 讨论(0)
提交回复
热议问题