简体   繁体   English

如果其中一列具有相同的数据,如何通过从每列中选择几列来连接两个数据帧

[英]how to join two dataframe by picking couple of column from each if one of the column has same data

there are two dataframes df_one and df_two I want to create a new data frame by with selective column from each of the dataframes有两个数据df_onedf_two我想通过每个数据框的选择性列创建一个新的数据框

df_one
e b c d 
1 2 3 4 
5 6 7 8 
6 2 4 8 
9 2 5 6

and

df_two

e f g h
1 8 7 6 
5 6 6 4 
6 6 2 4 
9 5 3 2 

I want to create a new dataframe new_df我想创建一个新的数据框 new_df

e b g h d
1 6 7 6 4
5 2 6 4 8
6 2 2 4 8
9 2 3 2 6

enter image description here在此处输入图片说明

 result = pd.merge(df_one, df_two, on='e')
 result=result.loc[:,["e","b","g","h","d"]]

用:

pd.merge(df1[["e", "b", "d"]], df2[["e", "g", "h"]], on="e")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何连接两个 dataFrame,其中一列具有相同的值(和名称)且大小相同? - How to join two dataFrame where one column having same values(and name) with same size? 连接两个数据帧,dataframe 中的一列具有多值数据 - Join two data frames, with one column in a dataframe having multivalue data 如何将两个数据帧中的一列连接到另一个数据帧? pd.merge 返回 nan - How to join one column from two dataframes to another dataframe ? pd.merge returns nan 如何从两个不同的数据帧中各取一列制作新的数据帧 - How to take one column each from two different dataframes making a new dataframe 如何在同一只熊猫数据框的一列中执行两项聚合操作? - How to perform two aggregate operations in one column of same pandas dataframe? 如何将一个数据框中的列表列与另一数据框中的字符串列连接在一起? - How to join a column of lists in one dataframe with a column of strings in another dataframe? 如果每列每行有多个值,如何在熊猫数据框中的两列之间创建字典? - How can I create a dictionary between two columns within a pandas dataframe if each column has more than one value per row? 如何基于一个数据框中的一列和第二个数据框中的两列合并两个数据框 - How to merge two data frames based on one column in one data frame and two column in second dataframe 如何连接来自同一数据帧的2列,但将第1列的a到d行和第2列的m到p联接? - How to join 2 columns from same dataframe, but taking rows a to d from column 1 and m to p from column 2? 如何将一个熊猫数据框的一列与另一个数据框的每一列相加? - How to sum a column of one pandas dataframe to each column of another dataframe?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM