Skip to content

Instantly share code, notes, and snippets.

@loganwilliams

loganwilliams/graph.py Secret

Created Apr 22, 2021
Embed
What would you like to do?
twint = pd.read_csv('tweets.csv', sep='\t', parse_dates=['created_at'])
twint['o2'] = twint['tweet'].apply(lambda v: 'oxygen' in v.lower() or 'o2' in v.lower())
grp = twint.groupby(pd.Grouper(freq='4H', key='created_at'))
plt.figure(figsize=(6,3))
plt.fill_between(grp.count().index, 0.25*grp.count()['id'], color="#fc8d62", alpha=1.0)
plt.fill_between(grp.sum().index, 0.25*grp.sum()['o2'], color='#7570b3', alpha=1.0)
plt.xlim(pd.to_datetime('2021-03-10'), pd.to_datetime('2021-04-22 16:00'))
plt.ylabel('Unique tweets per hour')
plt.legend(['Tweets containing "delhi" and "urgent"', 'Tweets also containing "oxygen"'], loc='upper left')
plt.tight_layout()
plt.savefig('India.png', dpi=300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment