Created
March 11, 2017 17:30
-
-
Save hitowaft/b10fb89c08cca5dc41833cd280278d80 to your computer and use it in GitHub Desktop.
tweet_analytics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding: utf-8 | |
import matplotlib as mpl | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
from datetime import datetime | |
df= pd.read_csv("/home/pi/tweets.csv") #ここにCSVファイルのパスを入れる | |
df_tweet1 = df[df["text"] .str.contains(u"死にたい") == True] #ここに抽出したいキーワードを入れる(以下2つも同様) | |
df_tweet2 = df[df["text"] .str.contains(u"お金") == True] | |
#df_tweet3 = df[df["text"] .str.contains(u"") == True] | |
ts = [datetime.strptime(x, "%Y-%m-%d %H:%M:%S +0000") for x in df_tweet1["timestamp"]] | |
ts = pd.to_datetime(ts) | |
ts = ts.to_period("M") | |
ts2 = [datetime.strptime(x, "%Y-%m-%d %H:%M:%S +0000") for x in df_tweet2["timestamp"]] | |
ts2 = pd.to_datetime(ts2) | |
ts2 = ts2.to_period("M") | |
""" | |
ts3 = [datetime.strptime(x, "%Y-%m-%d %H:%M:%S +0000") for x in df_tweet3["timestamp"]] | |
ts3 = pd.to_datetime(ts3) | |
ts3 = ts3.to_period("M") | |
""" | |
ts_counts = ts.value_counts() | |
ts_counts = ts_counts.sort_index() | |
ts_counts2 = ts2.value_counts() | |
ts_counts2 = ts_counts2.sort_index() | |
""" | |
ts_counts3 = ts3.value_counts() | |
ts_counts3 = ts_counts3.sort_index() | |
""" | |
ts_counts.plot(label = "wd") #ここにデータの名前を入れる。日本語入力できません。 | |
ts_counts2.plot(label = "No Money") | |
#ts_counts3.plot(label = "") | |
plt.legend() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment