刪除幾乎空的分類列有人可以幫我嗎?
我需要從資料庫中刪除具有一定百分比的缺失字元的分類列,同時我想刪除具有一定百分比的停滯值(不一定是 100%)的數字列。
謝謝。菲利斯
回覆:刪除幾乎空的分類列很好,謝謝。
快樂的
回覆:刪除幾乎空的分類列是的,這完全取決於你如何設定。第一個檢查是尋找每個列中最常見的值,並確定它是否高於或低於閾值百分比。不幸的是,缺失值不是一個值,因此它不可能是最常見的。這就是為什麼它不適用於數字列。它確實適用於字元列 b/c "" 缺失且為空字串值。
希望這有助於解釋事情。
如果您想要更精細的粒度,只需使用不同的策略以不同的百分比執行多個循環即可。回覆:刪除幾乎空的分類列嗨,msharp,感謝您的回覆。讓我們問另一個問題。百分比變數適用於分類列和數字列嗎?如果是的話,我可以對失蹤案件和停滯案件有兩個不同的價值嗎?
抱歉,我的問題可能很愚蠢,但我不是 jsl 語言專家。
快樂的
回覆:刪除幾乎空的分類列只需結合策略即可。就像是:
Names Default To Here( 1 );
dt = Current Data Table();
percent = 90;
delcols = {};
numRows = nrows(dt);
for(i=1; maxi=NCols(dt), i<=maxi, i++,
if(nrows(loc(aslist(column(dt,i)<<GETASMATRIX> numRows * 百分比/100,插入(delcols, i); , if(Col N Missing(column(dt,i)) > numRows *%/100, insert into(delcols, i); ); ); ); if(nitems(delcols) > 0, dt << 刪除欄位(delcols)); </GETASMATRIX>回覆:刪除幾乎空的分類列你好
我在下面的第二個表中嘗試了您的腳本,結果在這裡。
正如您所看到的,它能夠刪除幾乎所有所需的列,但第二個列 (col2) 則不能。我該怎麼做才能也刪除?
謝謝菲利斯


回覆:刪除幾乎空的分類列您也許可以使用先前發布的方法,但使用列的模式來處理小於 100% 的內容
Names Default To Here( 1 );
dt = Current Data Table();
percent = 90;
delcols = {};
numRows = nrows(dt);
for(i=1; maxi=NCols(dt), i<=maxi, i++,
if(nrows(loc(aslist(column(dt,i)< numRows * 百分比/100,插入(delcols, i); ); ); if(nitems(delcols) > 0, dt << 刪除欄位(delcols));
回覆:刪除幾乎空的分類列我想你也在尋找這樣的東西:
如果所有資料只有一個值,這將刪除數字列。
Names Default To Here( 1 );
dt = Current Data Table();
delcols = {};
numRows = nrows(dt);
for(i=1; maxi=NCols(dt), i<=maxi, i++,
col = column(dt, i);
try(summarize(dt, max = max(col), min = min(col));
if((max == min) | (ismissing(max)),
insertinto(delcols, i);
)
);
);
if(nitems(delcols) > 0, dt << delete columns(delcols));回覆:刪除幾乎空的分類列另一種方法,我相信稍微更穩健。
Names Default To Here( 1 );
dt = Current Data Table();
percent = 90;
delcols = {};
numRows = nrows(dt);
for(i=1; maxi=NCols(dt), i<=maxi, i++,
col = column(dt, i);
nmissing = col N missing(col);
if(nmissing > numRows * percent/100,
insert into(delcols, i);
);
);
if(nitems(delcols) > 0, dt << delete columns(delcols));
回覆:刪除幾乎空的分類列這是一個快速但骯髒的腳本,可以刪除資料少於指定百分比的列
Names Default To Here( 1 );
dt = Current Data Table();
percent = 90;
colList = dt << get column names( character, string );
NumRows = N Rows( dt );
For( i = N Items( colList ), i >= 1, i--,
If( Col Number( Column( dt, i ) ) / NumRows * 100 < percent,
dt << delete columns( colList[i] )
)
);