如果其中一个列具有相同的数据,如何通过从每个列中选择一对列来联接两个数据框 [英] how to join two dataframe by picking couple of column from each if one of the column has same data
本文介绍了如果其中一个列具有相同的数据,如何通过从每个列中选择一对列来联接两个数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有两个数据帧df_one
和df_two
我想通过每个数据帧中的选择列创建一个新的数据帧
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_one
e b c d
1 2 3 4
5 6 7 8
6 2 4 8
9 2 5 6
和
df_two
e f g h
1 8 7 6
5 6 6 4
6 6 2 4
9 5 3 2
我想创建一个新的数据框new_df
I want to create a new dataframe 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
推荐答案
result = pd.merge(df_one, df_two, on='e')
result=result.loc[:,["e","b","g","h","d"]]
这篇关于如果其中一个列具有相同的数据,如何通过从每个列中选择一对列来联接两个数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文