Python 熊猫中的isnull(col1,col2)等价物
如何为下面的SQL查询编写等效语句Python 熊猫中的isnull(col1,col2)等价物,python,sql,pandas,Python,Sql,Pandas,如何为下面的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() 我可能是误解了,但这不就是从dataframe1中选择id吗?直译类似于df=
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()
我可能是误解了,但这不就是从dataframe1中选择id吗?直译类似于
df=df1.merge(df2,on='id',how='left');df['id'].fillna(df['id'])
@chrisb左连接在左侧有df1
。这意味着右边的df2
可能有df2.id
的NULL
值。