1# when you wrap conditions in parantheses, you give order
2# you do those in brackets first before 'and'
3# AND
4movies[(movies.duration >= 200) & (movies.genre == 'Drama')]
5
1df.loc[(df['Salary_in_1000']>=100) & (df['Age']< 60) & (df['FT_Team'].str.startswith('S')),['Name','FT_Team']]
2
1df.query('Salary_in_1000 >= 100 & Age < 60 & FT_Team.str.startswith("S").values')
2
1>>> df["A"][(df["B"] > 50) & (df["C"] == 900)]
22 5
33 8
4Name: A, dtype: int64
5
6>>> df.loc[(df["B"] > 50) & (df["C"] == 900), "A"]
72 5
83 8
9Name: A, dtype: int64
10>>> df.loc[(df["B"] > 50) & (df["C"] == 900), "A"].values
11array([5, 8], dtype=int64)
12>>> df.loc[(df["B"] > 50) & (df["C"] == 900), "A"] *= 1000
13>>> df
14 A B C
150 9 40 300
161 9 70 700
172 5000 70 900
183 8000 80 900
194 7 50 900
20
1# Create variable with TRUE if nationality is USA
2american = df['nationality'] == "USA"
3
4# Create variable with TRUE if age is greater than 50
5elderly = df['age'] > 50
6
7# Select all cases where nationality is USA and age is greater than 50
8df[american & elderly]