[문제]
https://leetcode.com/problems/not-boring-movies/
[풀이]
1. 조건1) 모듈 연산으로 id가 홀수인 행 필터링
2. 조건2) != 연산으로 description이 boring이 아닌 행 필터링
3. rating으로 내림차순 정렬
Pandas
import pandas as pd
def not_boring_movies(cinema: pd.DataFrame) -> pd.DataFrame:
cond1 = cinema['id'] % 2 == 1
cond2 = cinema['description'] != 'boring'
return cinema[cond1 & cond2].sort_values(by='rating', ascending=False)
SQL
# Write your MySQL query statement below
SELECT *
FROM Cinema
WHERE id % 2 = 1 AND description != 'boring'
ORDER BY rating DESC
'코딩 테스트 > Pandas' 카테고리의 다른 글
Project Employees I (0) | 2024.12.26 |
---|---|
Average Selling Price (0) | 2024.12.25 |
Confirmation Rate (0) | 2024.12.24 |
Managers with at Least 5 Direct Reports // agg()와 query() (0) | 2024.12.23 |
Students and Examinations (0) | 2024.12.22 |