我有以下数据框:
而且,对于数据框中的每一列,我都在尝试计算与简单线性回归有关的以下方程:
这些公式要求我能够参考每个列中的两个值(x_i)以及他们的行索引/名称(y_i),以及行索引和实际列值的平均值。我该怎么做?我知道这是一个经验法则,永远不要在数据框架上迭代,但是,考虑到此框架的尺寸很小,我真的不在乎它是如何完成的。
I've got the following dataframe:
and, for every column in the dataframe, I'm attempting to calculate the following equations relating to simple linear regression:
These formulas require me to be able to reference both the values in each column (x_i) and their row index/name (y_i), along with the mean of both the row indices and the actual column values. How can I do this? I know that it's a rule of thumb never to iterate over a dataframe, but, given the small size of this frame, I really don't care how it's done.
发布评论
评论(1)
您可以通过
apply()
函数进行操作。您可以访问每行的“ x”值和“ y”值(索引)。示例数据框:
然后访问
apply()
函数中每一行的值:敲除这些方程将取决于您。
You could do it via an
apply()
function. You can access the 'x' values and the 'y' value (index) for each row.Sample DataFrame:
Then access then values for each row in an
apply()
function:Knocking out those equations will be up to you.