Woorden tellen

Socialmediagegevens analyseren in Python

Alex Hanna

Computational Social Scientist

Waarom woorden tellen?

  • Basisstap voor het automatiseren van tekstanalyse
  • Laat zien hoe vaak een relevant trefwoord voorkomt t.o.v. andere woorden
  • In oefeningen: #rstats vs #python
Socialmediagegevens analyseren in Python

Tellen met str.contains

  • str.contains
    • pandas-Series-stringmethode
    • Geeft booleaanse Series terug
    • case = False - niet hoofdlettergevoelig zoeken
Socialmediagegevens analyseren in Python

Companies-gegevensset

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
Socialmediagegevens analyseren in Python

Tellen in meerdere tekstvelden

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
Socialmediagegevens analyseren in Python

Laten we oefenen!

Socialmediagegevens analyseren in Python

Preparing Video For Download...