본문 바로가기

Algorithm/Python

[stratascratch] Order Details(Python)

문제

Find order details made by Jill and Eva. Consider the Jill and Eva as first names of customers. Output the order date, details and cost along with the first name. Order records based on the customer id in ascending order.

Jill과 Eva가 만든 주문을 찾아서 주문 날짜, 상세 내역 및 비용을 이름과 함께 출력하기
고객 ID를 기준으로 오름차순으로 정렬

코드

# Import your libraries
import pandas as pd

# Start writing code
result = pd.merge(customers, orders, how="inner", left_on="id", right_on="cust_id").sort_values('cust_id')
cond = (result["first_name"] == 'Jill') | (result["first_name"] == 'Eva')
result[cond][["first_name", "order_date", "order_details", "total_order_cost"]]

출처

반응형