For a df that looks like this
d = {'age' : [21, 45, 45, 5],
'salary' : [20, 40, 10, 100]}
df = pd.DataFrame(d)
df
age salary
0 21 20
1 45 40
2 45 10
3 5 100
I am trying to add a column with boolean if condition is met
df['stat'] = df['salary'] < 40
df
age salary stat
0 21 20 True
1 45 40 False
2 45 10 True
3 5 100 False
however when i assign the same condition to a variable i dont see true or false column
x1 = df['salary'] < 40
df[x1]
age salary
0 21 20
2 45 10
What is a best way to retain all rows but to add a column if a condition/s is met
If i have multiple condition something like below in
>>> x2 = df['age'] < 25
df[x1 & x2]
age salary
0 21 20
I would like to return all rows but with a stat column that would indicate T or F.