인프런 커뮤니티 질문&답변
에러해결방법
작성
·
1.9K
0
아래 for in 구문을 돌리는데 이런 경고가 나옵니다.
퍼포먼스를 높이면서 이런 경고문을 안 나오게 하려면
어떤 방식으로 짜는 게 좋을까요?
for indicator in tqdm(indicators_Value):
df_팩터정규화[f"{indicator}_Yield"] = df_팩터정규화[indicator] / df_팩터정규화["시가총액"]
| 0/238 [00:00<?, ?it/s]<ipython-input-2-9bd50d5ff602>:64: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
df_팩터정규화[f"{indicator}_Yield"] = df_팩터정규화[indicator] / df_팩터정규화["시가총액"]
퀴즈
Pandas에서 GroupBy와 Aggregation의 주된 목적은 무엇일까요?
데이터프레임의 모든 행을 순회하며 값을 개별적으로 수정하기 위함입니다.
데이터를 특정 기준으로 그룹화하고, 각 그룹별로 요약 통계 등을 계산하기 위함입니다.
두 개 이상의 데이터프레임을 단순히 하나의 데이터프레임으로 합치기 위함입니다.
대규모 데이터셋의 메모리 사용량을 최소화하기 위함입니다.
답변 1
1
안녕하세요!
cols = ["indicator1", "indicator2", "indicator3"]
new_cols = [f"{col}_yield" for col in cols]
df.loc[:, new_cols] = df.loc[df[cols].divide(df["시가총액"], axis=0)
요런식으로하면 벡터연산 딱 한번에 다 처리 가능할 것 같습니다 : )




