Union in more than 2 pandas dataframe

前端 未结 3 1138
死守一世寂寞
死守一世寂寞 2021-02-20 04:38

I am trying to convert a sql query to python. The sql statement is as follows:

select * from table 1 
union
select * from table 2
union 
select * from table 3
un         


        
3条回答
  •  被撕碎了的回忆
    2021-02-20 05:10

    This should be a comment on Jezrael's answer (+1'd for merge over concat) but I haven't sufficient reputation.

    The OP asked how to union the dfs, but merge returns intersection by default: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html#pandas.merge

    To get unions, add how='outer' to the merge calls.

提交回复
热议问题