Đếm từ

Phân tích dữ liệu mạng xã hội bằng Python

Alex Hanna

Computational Social Scientist

Vì sao đếm từ?

  • Bước cơ bản để tự động hóa phân tích văn bản
  • Cho biết một từ khóa liên quan xuất hiện bao nhiêu lần trong tài liệu so với từ khác
  • Trong bài tập: #rstats vs #python
Phân tích dữ liệu mạng xã hội bằng Python

Đếm với str.contains

  • str.contains
    • Phương thức chuỗi của pandas Series
    • Trả về Series kiểu boolean
    • case = False - tìm kiếm không phân biệt hoa/thường
Phân tích dữ liệu mạng xã hội bằng Python

Bộ dữ liệu Companies

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
Phân tích dữ liệu mạng xã hội bằng Python

Đếm ở nhiều trường văn bản

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
Phân tích dữ liệu mạng xã hội bằng Python

Cùng luyện tập nào!

Phân tích dữ liệu mạng xã hội bằng Python

Preparing Video For Download...