728x90
컬럼 값에 포함되지 않는 경우
df의 데이터 중 choice_description 값에 Vegetables 들어가지 않는 경우의 갯수를 출력하라
df.head()
order_id quantity item_name choice_description item_price new_price
0 1 1 Chips and Fresh Tomato Salsa NoData $2.39 2.39
1 1 1 Fizzy Lizzy [Clementine] $3.39 3.39
2 1 1 Nantucket Nectar [Apple] $3.39 3.39
3 1 1 Chips and Tomatillo-Green Chili Salsa NoData $2.39 2.39
4 2 2 Chicken Bowl [Tomatillo-Red Chili Salsa (Hot), [Black Beans... $16.98 16.98
일 때,
우선 포함하는 경우를 찾는다.
df['choice_description'].str.contains('Vegetables' , case = False)
0 False
1 False
2 False
3 False
4 False
...
4617 False
4618 False
4619 True
4620 True
4621 True
이 값에서 True와 False를 맞바꾸면 True 값이 Vegetables를 포함하지 않는 경우다.
이때 제일 앞에 ~ 를 넣어준다.
~df['choice_description'].str.contains('Vegetables' , case = False)
0 True
1 True
2 True
3 True
4 True
...
4617 True
4618 True
4619 False
4620 False
4621 False
Name: choice_description, Length: 4622, dtype: bool
이렇게 Vegetables를 포함하지 않는 경우가 True로 출력된다.
728x90
'python > pandas' 카테고리의 다른 글
pandas - Series에서 문자열 컬럼 슬라이싱하기 (.str) (0) | 2022.11.30 |
---|---|
pandas - 라이브러리 설치하기 (0) | 2022.11.29 |
pandas - 히스토그램 만들기(.hist) ,bins 설정 (0) | 2022.11.28 |
pandas - 차트 안에 넣는 한글 처리 코드 (0) | 2022.11.28 |
pandas - 두 컬럼간의 관계를 상관계수로 구하기( Correlation coefficient) (0) | 2022.11.28 |