[英]How to join two dataframes columnwise?
I have two dataframes df1
and df2
containing an equal number of columns.我有两个数据df1
和df2
包含相同数量的列。 I want to create another dataframe df
by joining df1
and df2
.我想通过加入df1
和df2
创建另一个 dataframe df
。
The resulting dataframe should be formed by selecting column1
from df1
and column1
from df2
and join them together.生成的 dataframe 应通过从df1
中选择column1
和从df2
中选择column1
并将它们连接在一起来形成。 Similarly column2
from df1
and column2
from df2
and so on.类似地,来自df1
的column2
和来自df2
的column2
等等。
Try this:尝试这个:
You can replace 'Column 1' and 'Column 2' with whatever name is required in your context.您可以将“Column 1”和“Column 2”替换为上下文中所需的任何名称。
import pandas as pd
df = pd.merge(df1, df2, on=['Column 1','Column 2'], how = 'outer')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.