Skip to content

Instantly share code, notes, and snippets.

@hitowaft
Last active March 30, 2017 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitowaft/dfe864537964418a684a6f350c1e71ae to your computer and use it in GitHub Desktop.
Save hitowaft/dfe864537964418a684a6f350c1e71ae to your computer and use it in GitHub Desktop.
# coding: utf-8
# In[1]:
import pandas as pd
import matplotlib.pyplot as plt
# In[2]:
tweet_df = pd.read_csv("/hoge/tweets.csv", parse_dates=["timestamp"]) #ここにダウンロードしたcsvファイルのパスを入れる
tweet_df = tweet_df.set_index(["timestamp"])
tweet_df = tweet_df.reindex(columns=["text"])
# In[3]:
columns = {"Yohei":"洋平|ようぺ", "Ichiro":"一郎"} #ここにグラフにしたいワードを入れる
for k, v in columns.items():
tweet_df["{}".format(k)] = tweet_df["text"].str.contains("{}".format(v))
tweet_df = tweet_df.drop(["text"], axis=1)
# In[4]:
tweet_df = tweet_df.resample("M").sum()
tweet_df.plot()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment