你好,
我有一列 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