在超过2个 pandas 数据框中合并 [英] Union in more than 2 pandas dataframe
问题描述
我正在尝试将sql查询转换为python。 sql语句如下:
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
现在我在4个数据帧中有这些表 df1,df2,df3,df4
,我想合并4个与结果匹配的熊猫数据帧与sql查询相同。
我对要使用的等效于SQL Union的操作感到困惑?
预先感谢!
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.
推荐答案
如果我对问题很了解,那么您正在寻找 concat
函数。
If I understand well the issue, you are looking for the concat
function.
pandas.concat([df1,df2,df3,df4])
如果列名称为两个数据框都一样。
pandas.concat([df1, df2, df3, df4])
should work correctly if the column names are the same for both dataframes.
这篇关于在超过2个 pandas 数据框中合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!