본문 바로가기
Python_Wiki/Python_Library

library 업데이트에 따른 경고문 + 대체한 입력 방법

by yj-data 2025. 6. 6.

구글 콜랩을 사용하면서 마주한 업데이트 경고문을 작성하는 글이다. 

 

1. pandas fillna, replace inplace (2025.6월)

  • e.g. df.fillna('No Data', inplace = True) (inplace는 원본 객체 변경을 위한 함수)
  • 에러문: FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method. The behavior will change in pandas 3.0. This inplace method will never work because the intermediate object on which we are setting values always behaves as a copy.
  • 대체 방법: For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)' or df[col] = df[col].method(value) instead, to perform the operation inplace on the original object.
  • example
# don't : disney['director'].fillna('No Data', inplace=True) 
# do:
disney.fillna({'director':'No Data'}, inplace=True)
disney['director'] = disney['director'].fillna('No Data')
disney['cast'] = disney['cast'].replace(np.nan, 'No Data')