Drop rows with multiple keys in pandas -


i have 2 dataframes, df1 , df2.

df1:

contig  position   tumor_f  t_ref_count  t_alt_count 1     14599  0.000000            1            0 1     14653  0.400000            3            2 1     14907  0.333333            6            3 1     14930  0.363636            7            4  

df2:

contig  position 1     14599 1     14653 

i remove rows df1 matching contig, position values in df2. akin to: df1[df1[['contig','position']].isin(df2[['contig','position']])] except doesn't work.

version .13 adding isin method dataframe accomplish this. if you're using current master can try:

in [46]: df1[['contig', 'position']].isin(df2.to_dict(outtype='list')) out[46]:    contig position 0   true     true 1   true     true 2   true    false 3   true    false 

to elements not contained use ~ not , index

in [45]: df1.ix[~df1[['contig', 'position']].isin(df2.to_dict(outtype='list')). all(axis=1)] out[45]:     contig  position   tumor_f  t_ref_count  t_alt_count 2       1     14907  0.333333            6            3 3       1     14930  0.363636            7            4 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -