我的資料集:
data={'A':['1210226','1210226','1210226','1210302','1210336','1210336','1210336'],'B':['','','[email protected]','[email protected]','','','[email protected]']}
df=pd.DataFrame(data)
print(df)
我將列過濾為excel == python中的空白(使用is.null)
excel中的資料集

我想在 pandas 中應用的條件是 =IF(A1=A3,B3,"") 公式是用 excel 撰寫的(請查看圖片),并且作業表被空白過濾。我知道 O 必須使用 is.null() 然后我想將條件應用于 is.null 以獲得所需的輸出。

最終輸出應如下圖所示

uj5u.com熱心網友回復:
您可以嘗試以下方法:
data={'A':['1210226','1210226','1210226','1210302','1210336','1210336','1210336'],'B':['','','[email protected]','[email protected]','','','[email protected]']}
df=pd.DataFrame(data)
df.drop("B", axis=1).merge(df.groupby("A").max(), on="A")
輸出:
A B
0 1210226 2@.com
1 1210226 2@.com
2 1210226 2@.com
3 1210302 1@.com
4 1210336 1@.com
5 1210336 1@.com
6 1210336 1@.com
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/415589.html
標籤:
上一篇:如何使用glob.glob(path)以自然排序順序遍歷檔案夾中的檔案?
下一篇:pygame不更新x和y
