What is the difference between 'and', '&', and '|'?
For example, in the code below,
i = df[((df.group == 'control') & (df.landing_page == 'new_page')) | ((df.group == 'treatment') & (df.landing_page == 'old_page'))].index
What is the difference between 'and', '&', and '|'?
For example, in the code below,
i = df[((df.group == 'control') & (df.landing_page == 'new_page')) | ((df.group == 'treatment') & (df.landing_page == 'old_page'))].index
The and is a type of Logical AND that returns in a True form whenever both the operands are also true. The ‘and’ expression tests if both the expressions used are True (logically).
The &, on the other hand, is a bitwise operator used in the Python language. It basically acts on various bits and performs operations bit by bit. The ‘&’ expression, on the other hand (when used with False/ True values), tests if both of these are True.
the | Each bit position in the result is the logical OR of the bits in the corresponding position of the operands. (1 if either is 1, otherwise 0.)