Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 熊猫中的isnull(col1,col2)等价物_Python_Sql_Pandas - Fatal编程技术网

Python 熊猫中的isnull(col1,col2)等价物

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=

如何为下面的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=df1.merge(df2,on='id',how='left');df['id'].fillna(df['id'])
@chrisb
左连接在左侧有
df1
。这意味着右边的
df2
可能有
df2.id
NULL
值。