EDA 플롯 II
또 떠오르는 아이디어는, 하루 중 시간대에 따라 요금이 달라질 수 있다는 점이에요.
여러분의 목표는 하루 24시간 각각에 대해 중간 fare_amount를 간단한 선 그래프로 그리는 것입니다. hour 특성은 미리 계산되어 있어요. 날짜 관련 특성을 다루는 방법을 아직 모르셔도 걱정하지 마세요. 특징 공학 챕터에서 자세히 살펴볼 거예요.
이 연습은 강의의 일부입니다
Python으로 Kaggle 대회 공략하기
연습 안내
trainDataFrame을"hour"로 그룹화하고"fare_amount"열의 중앙값을 계산하세요.- 생성된
hour_priceDataFrame을 사용해, x축에는"hour", y축에는"fare_amount"를 두고 선 그래프를 그리세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Create hour feature
train['pickup_datetime'] = pd.to_datetime(train.pickup_datetime)
train['hour'] = train.pickup_datetime.dt.hour
# Find median fare_amount for each hour
hour_price = train.____('____', as_index=False)['____'].____()
# Plot the line plot
plt.plot(hour_price[____], hour_price[____], marker='o')
plt.xlabel('Hour of the day')
plt.ylabel('Median fare amount')
plt.title('Fare amount based on day time')
plt.xticks(range(24))
plt.show()