如下两个数据框,我想计算相关系数。
当两列都用实际值完成时,它工作正常。但如果不是,则在计算相关系数时取零作为值。
例如,Addison 和 Caden 的权重为 0。Jack 和 Noah 没有权重。我想排除它们进行计算。
(在尝试中,似乎只考虑相同的长度,即自动排除 Jack 和 Noah – 是吗?)
如何只包括非零值的人进行计算?
谢谢你。
import pandas as pd
Weight = {'Name': ["Abigail","Addison","Aiden","Amelia","Aria","Ava","Caden","Charlotte","Chloe","Elijah"],
'Weight': [10, 0, 12, 20, 25, 10, 0, 18, 16, 13]}
df_wt = pd.DataFrame(Weight)
Score = {'Name': ["Abigail","Addison","Aiden","Amelia","Aria","Ava","Caden","Charlotte","Chloe","Elijah", "Jack", "Noah"],
'Score': [360, 476, 345, 601, 604, 313, 539, 531, 507, 473, 450, 470]}
df_sc = pd.DataFrame(Score)
print df_wt.Weight.corr(df_sc.Score)
翻阅古今
MMMHUHU
相关分类