你好,
我有一列 A(大约 15,000 行),其中包含数字和许多空值(可能 70-80% 为空)。
我想构造一个 B 列,它在第 i 行等于以下平均值:*来自 A* 的最后 10 个非空值
--> 这意味着取 A[row i-1] , A[row i-2], ... 并返回直到你有 10 个非空值(或者如果你到达第 1 行然后取任意数字 <= 10你得到的非空值)
除了均值、中位数和众数之外,我还想做一个平滑版本的众数,其中:
我首先对 10 个非空值进行高斯平滑......并采用该分布的 argmax(模式)。
感谢您的任何想法或建议!
***
解决方案的想法:我的一个想法是因为我想用最后 10 个非空值进行几个不同的计算,我应该首先构造一个列 C,其条目是等于最后 10 个非空值的数组......然后我可以做 3 个在 C 列上运行的公式,以产生 B1(平均值)、B2(中间)、B3(平滑模式)。
以下是一些构建此列 C 数组的代码片段:
//step 1 grab the last say 50 entries (some fixed amount that will likely have 10 non-nulls)
For Each Row( dt_join,
to = Row();
If( to - 50 < 0,
from = 1,
from = to - 50); // Quantile( 0.5,
values = :away_1g_pull_seconds[Index( From, To )] < 50, Break());
);
//step 2 convert array to list, drop nulls, convert list of first 10 entries back to array ...
//I don't know how to assign this to a row of C
num_lag = 10;
values = dt_join:A[Index( From, To )] ;
MyList = Remove(as list(values)[1], as list(Loc(as list(values)[1], .)) ); //convert array to list and remove nulls
Mat = Number Col Box("", MyList[1:10]) << get as matrix; //hack convert to array