본문 바로가기
Programming/Python

[Python] Pandas 'settingWithCopyWarning' 경고 메세지 없애기

by a voyager 2021. 5. 9.
728x90
반응형

증상 

df2 = df[['A']]
df2['A'] /= 2

df2
     A
0  2.5
1  4.5
2  3.5

 

해결 방법 

1. (recommended) Use loc to lice subsets 

df2 = df.loc[:, ['A']]
df2['A'] /= 2     # Does not raise 

 

2. pd.options.mode.chained_assignment 모드 변경 

 pd.options.mode.chained_assignment = None
 df2['A'] /= 2

 

3. Make a deepcopy 

 df2 = df[['A']].copy(deep=True)
 df2['A'] /= 2

 

 

References

 

728x90
반응형

댓글