Skip to content
Advertisement

Tag: conditional-statements

if else Conditions

The problem is like this My solution: Now, if I enter 18 then it should be printed “Weird”. But it is showing “Not Weird”. I am not getting where the problem of my code is. Answer The operator & is the bitwise and operation. You need logical AND, instead, and it is done by means of and keyword. Just replace

Pandas: add column with progressive count of elements meeting a condition

Given the following dataframe df: I want to add another column that counts, progressively, the elements with df[‘B’]=’yes’: How can I do this? Answer You can use numpy.where with cumsum of boolean mask: Another solution is count boolean mask created by filtering and then add 0 values by reindex: Performance (in real data should be different, best check it first):

Advertisement