Python으로 하는 ETL과 ELT
Jake Roach
Data Engineer
다운스트림 사용자에게 가치를 제공하려면 데이터를 올바르게 변환해야 합니다

pandas는 표 형식 데이터를 변환하는 강력한 도구를 제공합니다
.loc[].to_datetime().loc[]를 사용하면 DataFrame의 두 차원을 모두 변환할 수 있습니다
# Keep only non-zero entries
cleaned = raw_stock_data.loc[raw_stock_data["open"] > 0, :]
# Remove excess columns
cleaned = raw_stock_data.loc[:, ["timestamps", "open", "close"]]
# Combine into one step
cleaned = raw_stock_data.loc[raw_stock_data["open"] > 0, ["timestamps", "open", "close"]]
.iloc[]는 정수 인덱싱을 사용해 DataFrame을 필터링합니다
cleaned = raw_stock_data.iloc[[0:50], [0, 1, 2]]
다운스트림 사용 사례를 위해 데이터 유형을 변환해야 하는 경우가 많습니다
.to_datetime()# "timestamps" column currectly looks like: "20230101085731"
# Convert "timestamps" column to type datetime
cleaned["timestamps"] = pd.to_datetime(cleaned["timestamps"], format="%Y%m%d%H%M%S")
Timestamp('2023-01-01 08:57:31')
# "timestamps" column currently looks like: 1681596000011
# Convert "timestamps" column to type datatime
cleaned["timestamps"] = pd.to_datetime(cleaned["timestamps"], unit="ms")
Timestamp('2023-04-15 22:00:00.011000')
데이터 변환에는 다음과 같은 위험이 따릅니다:
# Several ways to investigate a DataFrame
cleaned = raw_stock_data.loc[raw_stock_data["open"] > 0, ["timestamps", "open", "close"]]
print(cleaned.head())
# Return smallest and largest records
print(cleaned.nsmallest(10, ["timestamps"]))
print(cleaned.nlargest(10, ["timestamps"]))
Python으로 하는 ETL과 ELT