일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
- word2vec
- Websocket
- (깃)git bash
- java
- r
- RESFUL
- test
- lda
- 지마켓
- 이력서
- pytorch
- oracle
- jsp 파일 설정
- mysql
- Gmarket
- Python
- 크롤링
- 방식으로 텍스트
- 네이버뉴스
- 자바
- 토픽추출
- 과학백과사전
- 幼稚园杀手(유치원킬러)
- 파이썬
- Topics
- 게시판 만들기
- 코사인 유사도
- spring MVC(모델2)방식
- db
- tomoto
- Today
- Total
무회blog
python: 파이썬 특정 문자 개수 세어 보기 본문
-사용코드
txt = 'Show me the money.'
word_1 = txt.count('S')
word_2 = txt.count('o')
word_3 = txt.count('m')
print(word_1)
print(word_2)
print(word_3)
Series 의 행 개수를 셀 때 s.size 와 같이 뒤에 () 가 없다는 것 조심해야 겠습니다.그리고 > count()는 Null 값이 아닌 행(count Non-null rows)만 세며,
> size() 는 Null 값인 행도 모두 포함해서 행(size of all rows)을 센다
는 것도 유념하면 좋겠습니다.
구분 |
pandas DataFrame (df) |
pandas Series (s) |
행 개수 세기 (row count) |
len(df) df.shape[0] len(df.index) |
len(s) s.size len(s.index) |
열 개수 세기 (column count) |
df.shape[1] len(df.columns) |
N/A |
Null 값이 아닌 행 개수 세기 (Non-null row count) |
df.count() |
s.count() |
그룹 별 행 개수 세기 (Row count per group) |
df.groupby(...).size() |
s.groupby(...).size() |
그룹 별 Null 값이 아닌 행 개수 세기 (Non-null row count per group) |
df.groupby(...).count() |
s.groupby(...).count() |
간단한 예제를 아래에 소개합니다.
numpy와 pandas 라이브러리 불러오고, DataFrame과 Series 데이터셋 만들어보겠습니다.
'Python' 카테고리의 다른 글
Python # 파이썬 + - * / 연산을 할수 있는 클래스 (파이썬클래스) + 상속 (1) | 2020.05.07 |
---|---|
python: python 파이썬 # html 태그 제거 (0) | 2020.04.26 |
requets Beautiful Soup 로 네이버 실시간 검색어 크롤링(스크래핑) 하기 (2) | 2020.04.25 |
파이썬 파일 전처리 0424 (0) | 2020.04.24 |
python: python 판다스 파일 쓰기 (0) | 2020.04.23 |