Python
파이썬Python pandas DataFrame 포함되지않는 문자 찾기 '~', contains()
왕현성
2022. 11. 29. 12:12
728x90
DataFrame은 다음과 같다
요구사항 : df의 데이터 중 choice_description 값에 Vegetables 들어가지 않는 경우의 갯수를 출력하라
df['choice_description'].str.contains('Vegetables',case=False) ## 먼저 포함되는 것을 찾는다.
(df['choice_description'].str.contains('Vegetables',case=False) == False).sum() ## ~을 알기 전에 내가 사용했던 코드,
~df['choice_description'].str.contains('Vegetables',case=False) ## 이것보다 간단한 방법이 있는 것을 알게된 후 ~을 사용한 코드
~을 사용하니 True와 False가 서로 바뀐 결과는 위 사진과 같습니다.