시간 데이터 다루기

스프레드시트 사용자를 위한 Pandas 조인

John Miller

Principal Data Scientist

.merge_ordered()로 조인

time-series merge no result

pd.merge_ordered(cleveland, dallas, on='Game_Date', 
                suffixes=['_CLE', '_DAL'])
스프레드시트 사용자를 위한 Pandas 조인

.merge_ordered()로 조인

time-series merge

pd.merge_ordered(cleveland, dallas, on='Game_Date', 
                suffixes=['_CLE', '_DAL'])
스프레드시트 사용자를 위한 Pandas 조인

데이터 보간

interpolate on merge

pd.merge_ordered(tc2, td2, on='Game_Date', 
                suffixes=['_CLE', '_DAL'], fill_method='ffill')
스프레드시트 사용자를 위한 Pandas 조인

데이터 보간

fgf

pd.merge_ordered(tc2, td2, on='Game_Date', 
                suffixes=['_CLE', '_DAL'], fill_method='ffill')
스프레드시트 사용자를 위한 Pandas 조인

가장 가까운 날짜-시간으로 병합

  • pandas.merge_asof()
  • 가장 가까운 날짜로 매칭
  • VLOOKUP(range_lookup=TRUE)와 유사
pd.merge_asof(left_df, right_df,
              direction='backward')

방향

  • "backward": 더 이른 값 중 가장 가까움

  • "forward": 같거나 더 늦은 값 중 가장 가까움

  • "nearest": 방향 무관, 가장 가까움

스프레드시트 사용자를 위한 Pandas 조인

merge_asof 예시

merge_asof

pd.merge_asof(temps, impacts,
              left_on='Game_Date', right_index=True, direction='backward')
스프레드시트 사용자를 위한 Pandas 조인

연습해 봅시다!

스프레드시트 사용자를 위한 Pandas 조인

Preparing Video For Download...