[英]Merge 2 dataframes
I have 2 dataframe 我有2个数据框
for ex: 例如:
df1: df1:
seq_id1 seq_id2
seq1_A seq2_B
seq2_A seq3_B
seq4_A seq9_B
seq9_A seq9_B
etc
and another dataframe such 还有另一个数据框
df2: df2:
sequences
seq2_A
seq9_A
and keep only in the first dataframe, the row where the ID in the dataframe is present, here it would be: 并且仅保留在第一个数据帧中,即该数据帧中ID所在的行,此处为:
newdataframe merged: newdataframe合并:
seq_id1 seq_id2
seq2_A seq3_B
seq9_A seq9_B
Thanks for your help :) 谢谢你的帮助 :)
here. 这里。 are the dataframe= First one with only 60 rows : df1 second one with with all seq ID: df2 Here the columns ["#qseqid'"]
in the first df has to match with the restricted df2 in the column ["seq2_id"]
是dataframe =第一个只有60行: df1第二个具有所有seq ID: df2这里第一个df中的列["#qseqid'"]
必须与列["seq2_id"]
的受限df2相匹配
I believe need for match column seq_id1
with df2['sequences']
use isin
with boolean indexing
: 我认为需要匹配列seq_id1
与df2['sequences']
使用isin
与boolean indexing
:
df1[df1['seq_id1'].isin(df2['sequences'])]
Or: 要么:
df = pd.merge(df1, df2, left_on='seq_id1', right_on='sequences')
If need match both columns of df1
: 如果需要匹配df1
两列:
df1[df1.isin(df2['sequences']).any(axis=1)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.