본문 바로가기

Algorithm/Python

(31)
[stratascratch] Highest Number Of Orders(Python) 문제 Find the customer who has placed the highest number of orders. Output the id of the customer along with the corresponding number of orders. 가장 많은 수의 주문을 한 고객을 찾아라 고객의 ID를 해당 주문 수와 함께 출력 코드 # Import your libraries import pandas as pd # Start writing code customers.head() # customers와 orders 조인 df = pd.merge(customers, orders, how="inner", left_on="id", right_on="cust_id") # id_x 별로 count 집계 df..
[stratascratch] Salaries Differences(Python) 문제 Write a query that calculates the difference between the highest salaries found in the marketing and engineering departments. Output just the difference in salaries. 마케팅 부서와 엔지니어링 부서 사이의 가장 높은 연봉 차를 계산하여 조회하기 코드 # Import your libraries import pandas as pd # Start writing code db_employee.head() df = pd.merge(db_employee, db_dept, how="inner", left_on="department_id", right_on="id") abs(df[(df..
[stratascratch] Number Of Units Per Nationality(Python) 문제 Find the number of apartments per nationality that are owned by people under 30 years old. Output the nationality along with the number of apartments. Sort records by the apartments count in descending order. 30세 미만 인구가 소유한 국적별 아파트 수 조회하기 아파트 수를 기준으로 내림차순 정렬 코드 # Import your libraries import pandas as pd # Start writing code airbnb_hosts.head() df = pd.merge(airbnb_hosts, airbnb_units, how="i..
[프로그래머스] 시저 암호 (Python) 문제 어떤 문장의 각 알파벳을 일정한 거리만큼 밀어서 다른 알파벳으로 바꾸는 암호화 방식을 시저 암호라고 합니다. 예를 들어 "AB"는 1만큼 밀면 "BC"가 되고, 3만큼 밀면 "DE"가 됩니다. "z"는 1만큼 밀면 "a"가 됩니다. 문자열 s와 거리 n을 입력받아 s를 n만큼 민 암호문을 만드는 함수, solution을 완성해 보세요. 코드 def solution(s, n): answer = [] for val in s: if val == ' ' : answer.append(' ') else : if val.islower(): # 소문자일 경우 answer.append(chr((ord(val) - ord('a') + n) % 26 + ord('a'))) elif val.isupper() : # 대문..