[英]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_one
和df_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
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.