単語をカウントする

Python でのソーシャルメディアデータ分析

Alex Hanna

Computational Social Scientist

なぜ単語をカウントするのか

  • テキスト分析を自動化する基本的なステップ
  • 関連するキーワードが他と比べて何回言及されているかを把握できる
  • 演習では #rstats と #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...