구글 콜랩을 사용하면서 마주한 업데이트 경고문을 작성하는 글이다.
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')'Python_Wiki > Python_Library' 카테고리의 다른 글
| 웹크롤링: Selenium + chrome driver (0) | 2025.07.10 |
|---|---|
| 산점도 맵 scatter map 그리기 (feat. matplotlib) (0) | 2025.06.11 |
| matplotlib: word cloud 워드 클라우드 (2) | 2025.06.06 |
| matplotlib/seaborn: heatmap 히트맵 (0) | 2025.06.06 |
| matplotlib: 꺾은선 그래프 line chart(fill_between) (0) | 2025.06.05 |