df.query('my_car_damage > 0') # my_car_damage가 0보다 큰 경우
df.query('model == "Avante" and my_car_damage > 0')
# 차종이 Avante이고 my_car_damage가 0보다 큰 경우
df.query('my_car_damage == 0 or other_car_damage == 0')
# my_car_damage가 0이거나 other_car_damage가 0인 경우
df.query('not (my_car_damage == 0)')
# my_car_damage가 0이 아닌 경우
변수 사용
@변수명을 사용하여 외부 변수를 쿼리 내에서 참조
last_year = df.year.max()
df.query('year == @last_year') # last_year 변수에 저장된 값과 year 열이 같은 행을 선택
문자열 내용으로 필터링
.str.contains('text'): 'text'를 포함하는지
.str.startswith('text'): 'text'로 시작하는지
.str.endswith('text'): 'text'로 끝나는지
예시:
df.query('model.str.contains("va")') # va를 포함
df.query('model.str.startswith("A")') # A로 시작
df.query('model.str.endswith("e")') # e로 끝남