两个数据帧如下,我想计算相关系数
当两列都用实际值完成时,它可以正常工作。但当它们不是时,在计算相关系数时取零
例如,艾迪生和卡登的重量是0。杰克和诺亚没有重量。我想把它们排除在外进行计算
(在尝试中,似乎只考虑相同的长度,即自动排除杰克和诺亚-是吗?)
如何只包含非零值的人进行计算
谢谢你
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)
掩蔽和获取非零值和公共索引:
如果两个数据帧都包含零,则:
使用^{} 添加新列,按^{} 删除
0
行,最后在同一数据帧中应用解决方案:相关问题 更多 >
编程相关推荐