text_html_output_1.png
from wordcloud import WordCloud, STOPWORDS

import datetime

import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

df = pd.read_excel('../input/tweets.xlsx', sheet_name='tweets')

pd.isnull(df).any()

toptweeps = df.groupby('username')[['tweet ']].count()
toptweeps.sort_values('tweet ', ascending=False)[:10]

topretweets = df.groupby('username')[['retweets']].sum()
topretweets.sort_values('retweets', ascending=False)[:10]

corpus = ' '.join(df['tweet '])
corpus = corpus.replace('.', '. ')
wordcloud = WordCloud(stopwords=STOPWORDS, background_color='white', width=2400, height=2000).generate(corpus)
plt.axis('off')

mest = df[df['username'] == 'MESTAfrica']
corpu = ' '.join(df['tweet '])
corpu = corpu.replace('.', '. ')
wordcloud = WordCloud(stopwords=STOPWORDS, background_color='white', width=2400, height=2000).generate(corpu)
plt.axis('off')

tony = df[df['username'] == 'TonyElumeluFDN']
corp = ' '.join(df['tweet '])
corp = corp.replace('.', '. ')
wordcloud = WordCloud(stopwords=STOPWORDS, background_color='white', width=2400, height=2000).generate(corp)
plt.axis('off')

df2 = df
df2['date'] = df2['created_at'].map(lambda x: x.split(' ')[0])
df2['time'] = df2['created_at'].map(lambda x: x.split(' ')[-1])
del df2['created_at']

month_order = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
day_order = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
df2 = df[['tweet_id', 'date', 'time', 'tweet ', 'retweets', 'username']]

df2['month'] = df2['date'].apply(lambda x: month_order[int(x.split('-')[1]) - 1])
month_df = pd.DataFrame(df2['month'].value_counts()).reset_index()
month_df.columns = ['month', 'tweets']

def getday(x):
    year, month, day = (int(i) for i in x.split('-'))
    answer = datetime.date(year, month, day).weekday()
    return day_order[answer]
df['day'] = df['date'].apply(getday)
day_df = pd.DataFrame(df['day'].value_counts()).reset_index()
day_df.columns = ['day', 'tweets']
plt.figure(figsize=(12, 6))
plt.title('All Tweets Per Day')
sns.barplot(x='day', y='tweets', data=day_df, order=day_order)