라이드 사이에 얼마나 걸렸을까요?
마지막 연습 문제에서는 Pandas 인덱싱을 활용해 흥미로운 작업을 해 보겠습니다. 라이드 사이에 경과한 시간은 얼마나 될까요?
이 연습은 강의의 일부입니다
Python에서 날짜와 시간 다루기
연습 안내
- 현재 행의
Start date와 이전 행의End date차이를 계산해rides['Time since']에 할당하세요. - 다루기 쉽도록
rides['Time since']를 초 단위로 변환하세요. Start date를 기준으로rides를 월별 버킷으로 리샘플링하세요.- 평균을 (60*60)으로 나누어, W20529가 다시 픽업되기 전 도크에서 기다린 평균 시간을 시간(hour) 단위로 구하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Shift the index of the end date up one; now subract it from the start date
rides['Time since'] = rides['Start date'] - (rides[____].shift(1))
# Move from a timedelta to a number of seconds, which is easier to work with
rides['Time since'] = rides['Time since'].____
# Resample to the month
monthly = rides.____('____', on = 'Start date')
# Print the average hours between rides each month
print(monthly['Time since'].____/(60*60))