如果df1的值在df2的范围内,则在df1中添加新列

时间:2019-06-08 23:20:26

标签: python python-3.x

比较两个数据帧。如果df1的值与df2列的值重叠,则应添加一个新列,其值为'Yes'或'No'。

条件:

if df1['chr'] == df2['chr']
   df1['Status'] = df1['position'].between(df2['start'],df2['end']
df1<tab separated>
name    chr position
res1    c1  98
res2    c4  143
res3    c1  108

df2<tab separated>
chr start   end
c1  78  97
c2  108 143
c1  143 108

输出:

res1    c1  98  no
res2    c4  143 no
res3    c1  108 yes 
def overlap_region(H3K27ac_file,snp_list):
    df1 = pd.read_csv(H3K27ac_file, sep="\t",header=None,header=0)
    df2 = pd.read_csv(snp_list, sep="\t",header=0)

    df1['position'].between(df2['start'],df2['end']

    print(df1)
x = overlap_region(x,y)

0 个答案:

没有答案