I have a below pseudocode which I need to write using pandas.
if group_min_size && group_max_size
if group_min_size == 0 && group_max_size > 0
if group_max_size >= 2
errors.add(:group_min_size, "must be greater than or equal to 2 and less than or equal to group_max_size (#{group_max_size})")
end
if group_max_size < 2
errors.add(:group_min_size, "must be greater than 2")
errors.add(:group_max_size, "must be greater than 2")
end
end
if group_min_size > 0 && group_max_size == 0
if group_min_size >= 2
errors.add(:group_max_size, "must be greater than or equal to #{group_min_size}")
end
if group_min_size < 2
errors.add(:group_min_size, "must be greater than 2")
errors.add(:group_max_size, "must be greater than 2")
end
end
end
I tried to break in smaller parts and write something like below-
m8 = ((~df['group_min_size'].notna() & ~df['group_min_size'].notna()) | ((~df['group_min_size'] == 0) & (~df['group_max_size'] > 2)) | (df['group_max_size'] >= 2))
This is for
if group_min_size == 0 && group_max_size > 0
if group_max_size >= 2
errors.add(:group_min_size, "must be greater than or equal to 2 and less than or equal to group_max_size (#{group_max_size})")
end
But is not quite working as expected.
Below is my test data -
group_min_size group_max_size
0 0.0 1.0
1 10.0 20.0
2 0.0 3.0
3 3.0 0.0
4 NaN NaN
5 2.0 2.0
6 2.0 2.0
7 2.0 2.0
8 2.0 2.0
Based on the psudo code logic, the output should be:
False
True
False
False
True
True
True
True
True
How do I write this logic in pandas?