단어 세기

Python으로 소셜 미디어 데이터 분석하기

Alex Hanna

Computational Social Scientist

단어를 세는 이유

  • 텍스트 분석 자동화의 기본 단계
  • 문서에서 관련 키워드가 얼마나 자주 언급되는지 비교 가능
  • 실습: #rstats vs #python
Python으로 소셜 미디어 데이터 분석하기

str.contains로 단어 세기

  • str.contains
    • pandas Series 문자열 메서드
    • 불리언 Series 반환
    • case = False - 대소문자 구분 없이 검색
Python으로 소셜 미디어 데이터 분석하기

기업 데이터셋

import pandas as pd

tweets = pd.DataFrame(flatten_tweets(companies_json))
apple = tweets['text'].str.contains('apple', case = False)
print(np.sum(apple) / tweets.shape[0])
0.112
Python으로 소셜 미디어 데이터 분석하기

여러 텍스트 필드에서 단어 세기

apple = tweets['text'].str.contains('apple', 
                                     case = False) 
for column in ['extended_tweet-full_text',
    'retweeted_status-text',
    'retweeted_status-extended_tweet-full_text']:
    apple = apple | tweets[column].str.contains('apple', 
                                                 case = False)

print(np.sum(apple) / tweets.shape[0])
0.12866666666666668
Python으로 소셜 미디어 데이터 분석하기

연습해 봅시다!

Python으로 소셜 미디어 데이터 분석하기

Preparing Video For Download...