我有两个熊猫DF,长度相同,都是366行,一列。DF #1有随机放置的零值,但DF #2没有零。我需要在DF #1中找到有零值的行,并将DF #2中相同行的值改为零。我试图找到DF #1和2之间的相关性,并需要在两个DF中零的行数相同。变量'x'是366x1,'y'也是366x1,下面的'y'变量有NaN值,我想把它们转换为零。谢谢你的帮助,因为我似乎在网上找不到解决方案。
#handle the NaN's - set to zero and set to zero in Vortex data for same rows
y.fillna(0)
def rsquared(x, y):
""" Return R^2 where x and y are array-like."""
slope, intercept, r_value, p_value, std_err = sp.stats.linregress(x, y)
return r_value**2
print(rsquared(x,y))
这是你想做的吗?
x.loc[x.index==y[y['column']==0].index,'column']=0
我假设两个数据框的列名都是'列',并且有相同的索引值。