stables=["usdt","usdc","tusd"]
我的名為“df”的資料框看起來像這樣(實際的資料框有數百行):
pairs apy network pool name
0 [eth, wbtc] 1.150699e 01 cometh cometh-eth-wbtc
1 [usdt, usdc] 1.814333e 01 cometh cometh-usdt-usdc
2 [must, pickle] 2.175891e 01 cometh cometh-must-pickle
3 [usdt, eth] 1.237610e 02 cometh cometh-usdt-eth
4 [eth, matic] 2.181968e 01 cometh cometh-eth-matic
“pairs”列有專案串列。如果“pairs”列串列中的任何專案未包含在上面提供的“stables”串列中,我想逐行洗掉整行。
在這種情況下,只有第二行(索引為 1)會保留在資料框中,因為這兩個專案都在上面提供的“穩定”串列中。
歡迎任何幫助。
謝謝
uj5u.com熱心網友回復:
假設該pairs列實際上包含字串串列,您可以分解該列,用于isin測驗哪些元素是stables串列的成員,然后使用 agroupby agg np.all來測驗初始行的所有元素是否都是stables:
temp = df.explode('pairs')
temp['keep'] = temp['pairs'].isin(stables)
temp = temp.groupby(level=0)['keep'].agg(np.all)
to_keep = df[temp]
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/415265.html
標籤:
