如何根據定義的條件交換數據框中的值?鑒于:DF[['Exchange','predictions']]Exchange predictions0 PINK <UNK>1 PINK <UNK>2 PINK <UNK>3 PINK <UNK>4 PINK <UNK>... ... ...490541 NASDAQ PINK490542 NaN PINK490543 NASDAQ PINK490544 NaN PINK490545 NASDAQ PINK僅當 Exchange 值為 NaN 并且預測值不是 < UNK > 時,我才希望將 Exchange 替換為預測中的值。
1 回答

幕布斯6054654
TA貢獻1876條經驗 獲得超7個贊
讓我們嘗試fillna部分條件Series
df.Exchange.fillna(df.loc[df['predictions'].ne('<UNK>'), 'predictions'], inplace=True)
df
Out[210]:
Exchange predictions
0 PINK <UNK>
1 PINK <UNK>
2 PINK <UNK>
3 PINK <UNK>
4 PINK <UNK>
... ...
490541 NASDAQ PINK
490542 PINK PINK
490543 NASDAQ PINK
490544 PINK PINK
490545 NASDAQ PINK
添加回答
舉報
0/150
提交
取消