處理 NLP 問題
我最終得到了一個大的特征資料集
dfMethod
Out[2]:
c0000167 c0000294 c0000545 ... c4721555 c4759703 c4759772
0 0 0 0 ... 0 0 0
1 0 0 0 ... 0 0 0
2 0 0 0 ... 0 0 0
3 0 0 0 ... 0 0 0
4 0 0 0 ... 0 0 0
... ... ... ... ... ... ...
3995 0 0 0 ... 0 0 0
3996 0 0 0 ... 0 0 0
3997 0 0 0 ... 0 0 0
3998 0 0 0 ... 0 0 0
3999 0 0 0 ... 0 0 0
[4000 rows x 14317 columns]
我想洗掉重復次數最少的列(即所有記錄總和最小的列)
所以如果我的列總和看起來像這樣
Sum of c0000167 = 7523
Sum of c0000294 = 8330
Sum of c0000545 = 502
Sum of c4721555 = 51
Sum of c4759703 = 9628
最后,我只想根據每列的總和保留前 5000 列?
我怎樣才能做到這一點?
uj5u.com熱心網友回復:
假設您有一個大資料框big_df,您可以使用以下內容獲取頂部列:
N = 5000
big_df[big_df.sum().sort_values(ascending=False).index[:N]]
打破這個:
big_df.sum() # Gives the sums you mentioned
.sort_values(ascending=False) # Sort the sums in descending order
.index # because .sum() defaults to axis=0, the index is your columns
[:N] # grab first N items
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/474482.html
下一篇:如何將一行0添加到資料框中
