DataFrame 병합하기
이번 연습에서는 ri와 weather_rating DataFrame을 병합해 새로운 DataFrame인 ri_weather를 만들어요.
두 DataFrame은 ri의 stop_date 열과 weather_rating의 DATE 열을 사용해 조인합니다. 다행히 날짜 형식이 정확히 일치하지만, 항상 그런 것은 아니에요!
병합을 마친 뒤, 이전 연습에서 저장해 둔 열인 stop_datetime을 인덱스로 설정할 거예요.
이 연습은 강의의 일부입니다
pandas로 경찰 활동 분석하기
연습 안내
riDataFrame의 형태를 확인하세요.- 왼쪽 조인(left join)으로
ri와weather_ratingDataFrame을 병합하세요. ri_weather의 형태를 확인하여, 열이 두 개 더 늘었고 행 수는ri와 동일한지 확인하세요.ri_weather의 인덱스를stop_datetime열로 교체하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Examine the shape of 'ri'
print(____)
# Merge 'ri' and 'weather_rating' using a left join
ri_weather = pd.merge(left=____, right=____, left_on='stop_date', right_on='DATE', how='____')
# Examine the shape of 'ri_weather'
print(____)
# Set 'stop_datetime' as the index of 'ri_weather'
ri_weather.set_index('____', inplace=____)