본문 바로가기
파이썬/팁

SettingWithCopyWarning: 의미

by 한국수달보호협회장 2022. 6. 21.
SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

빨간색으로 이런글자가 뜬 적이 종종있는데 데이터 중 일부를 가져왔을때 복사본만 수정할건지 원본도 수정할건지를 몰라서 프로그램에서 경고를 하는거라고 한다.

참고로 경고는 뜨지만 원본이 바뀌지는 않는다.

 

df.copy()를 이용하면 된다.

https://beneagain.tistory.com/31

 

Pandas df.copy()

복사에도 두 종류가 있다. https://mizykk.tistory.com/63 [Python] df.copy() :: 복사본 만들기 / 얕은복사 & 깊은 복사 판다스에는 데이터프레임의 복사본을 만들어주는 pandas.DataFrame.copy가 있다. 이는 a =..

beneagain.tistory.com

 

*pd.set_option('mode.chained_assignment', None) 명령어를 사용해도된다.

밑에 링크가 가장 친절하게 설명해준다.

 

https://m.blog.naver.com/wideeyed/221817400937

 

[Pandas] SettingWithCopy Warning or Error 해결방법

Pandas(판다스, 팬더스)에서 원본 Dataframe의 일부를 복사하거나 인덱싱 후 값을 수정할 때 발생할 수 ...

blog.naver.com

 

 

https://ahnty0122.tistory.com/98

 

[Python] 판다스 데이터프레임(pandas dataframe) SettingWithCopyWarning 해결

기존 데이터프레임 일부를 복사하거나 인덱싱 후 값을 수정할 때 종종 발생한다. 기존 데이터프레임을 가져와(복사) 다른 데이터프레임을 만들 때 원본을 수정할 지 복사본을 수정할 지 몰라서

ahnty0122.tistory.com

 

 

아무것도 설정안했을 때 default값은 중간에 'warn'이다.

 

 

 

https://velog.io/@cjw9105/Python-SettingWithCopyWarning-%EC%9B%90%EC%9D%B8

 

[Python] SettingWithCopyWarning 원인

데이터를 수정하던 중 복사본에 열을 추가할 때 복사본에만 추가할지, 원본에도 추가할지 알 수가 없어서 A value is trying to be set on a copy of a slice from a DataFrame. Try using .locrow_indexer,

velog.io

https://emilkwak.github.io/pandas-dataframe-settingwithcopywarning

 

Pandas의 DataFrame 사용 중 SettingWithCopyWarning 발생할 때

Python, Pandas를 Excel보다 사랑하는 직장인을 위한 블로그

emilkwak.github.io