Once in a while I get to the point where I need to run the following line:
DF[‘is_flagged’] = DF[‘id’].isin(DF2[DF2[‘flag’]==1][‘id’])
Lately I started using polars, and I wonder how to convert it easily to polars.
Edit: For example:
df1 = polars.DataFrame._from_dict({
'Animal_id': [1, 2, 3, 4, 5, 6, 7],
'age': [4, 6, 3, 8, 3, 8, 9] })
df2 = polars.DataFrame._from_dict({
'Animal_id': [1, 2, 3, 4, 5, 6, 7],
'Animal_type': ['cat', 'dog', 'cat', 'cat', 'dog', 'dog', 'cat'] })
Output:
polars.DataFrame._from_dict({
'animal_id': [1, 2, 3, 4, 5, 6, 7],
'age': [4, 6, 3, 8, 3, 8, 9],
'is_dog': [0, 1, 0, 0, 1, 1, 0]})
Without using flag and then join
I tried to use the is_in() function but this didn’t worked.