Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Union in more than 2 pandas dataframe

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
union
select * from table 4

Now I have those tables in 4 dataframe df1, df2, df3, df4 and I would like to union 4 pandas dataframe which would match the result as the same as sql query. I am confused of what operation to be used which is equivalent to sql union? Thanks in advance!!

Note: The column name for all the dataframes are the same.

like image 720
User1090 Avatar asked Jan 08 '16 09:01

User1090


1 Answers

If I understand well the issue, you are looking for the concat function.

pandas.concat([df1, df2, df3, df4]) should work correctly if the column names are the same for both dataframes.

like image 150
Grégoire G. Avatar answered Oct 22 '22 05:10

Grégoire G.