Skip to main content
 首页 » 编程设计

python之isnull(col1,col2) 在 Pandas 中等效

2025年04月02日15xxx_UU

如何编写与以下 SQL 查询等效的语句?

SELECT ISNULL(df2.id, df1.id) as new_id 
FROM dataframe1 df1 
    LEFT JOIN dataframe2 df2 
    ON df1.id = df2.id 

请您参考如下方法:

一个这样的等价物是:

df2.set_index('id').combine_first(df1.set_index('id')).reset_index()