pandas - Selecting data from a dataframe based on a tuple -


suppose have following dataframe

df = dataframe({'vals': [1, 2, 3, 4],                 'ids': ['a', 'b', 'a', 'n']}) 

i want select rows in list

[ (1,a), (3,f) ] 

i have tried using boolean indexing so

to_search = { 'vals' : [1,3],           'ids'  : ['a', 'f']           }  df.isin(to_search) 

i expect first row match first , third row

     ids   vals 0   true   true 1   true  false 2   true   true 3  false  false 

is there way match values @ particular index instead of matching value?

you might create dataframe want match, , merge it:

in [32]: df2 = dataframe([[1,'a'],[3,'f']], columns=['vals', 'ids'])  in [33]: df.merge(df2) out[33]:    ids  vals 0       1 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -