Skip to content

Instantly share code, notes, and snippets.

@msarahan msarahan/sentiment_time.py
Last active Mar 18, 2016

Embed
What would you like to do?
def time_groups_to_plot_elements(slices, nbins=9):
"""Take the grouped time-sentiment relationships, and break it down into a single point/line for the plot"""
plot_data = {}
bins = np.linspace(-1.0, 1.0, nbins)
print bins
for k, v in slices.items():
binned_data = np.digitize(v["sentiment"], bins=bins) - 1
segments = np.zeros(nbins)
for bin_id in set(binned_data):
segments[bin_id] = v["sentiment"][binned_data==bin_id].count()
segments *= np.sign(bins)
plot_data[k] = segments
return plot_data
# example processed data:
{'MEGANEGATIVE': post_timestamp
2016-01-25 07:45:49.341873 -1
2016-01-26 07:45:49.341873 -0
2016-01-27 07:45:49.341873 -1
Name: MEGANEGATIVE, dtype: float64, 'Peachy': post_timestamp
2016-01-25 07:45:49.341873 0
2016-01-26 07:45:49.341873 0
2016-01-27 07:45:49.341873 2
Name: Peachy, dtype: float64, 'SHINYMETALAPPS': post_timestamp
2016-01-25 07:45:49.341873 0
2016-01-26 07:45:49.341873 2
2016-01-27 07:45:49.341873 1
Name: SHINYMETALAPPS, dtype: float64, 'cold': post_timestamp
2016-01-25 07:45:49.341873 -0
2016-01-26 07:45:49.341873 -2
2016-01-27 07:45:49.341873 -44
Name: cold, dtype: float64, 'gud': post_timestamp
2016-01-25 07:45:49.341873 1
2016-01-26 07:45:49.341873 2
2016-01-27 07:45:49.341873 22
Name: gud, dtype: float64, 'meh': post_timestamp
2016-01-25 07:45:49.341873 0
2016-01-26 07:45:49.341873 0
2016-01-27 07:45:49.341873 0
Name: meh, dtype: float64, 'nauseating': post_timestamp
2016-01-25 07:45:49.341873 -1
2016-01-26 07:45:49.341873 -1
2016-01-27 07:45:49.341873 -1
Name: nauseating, dtype: float64, 'warm': post_timestamp
2016-01-25 07:45:49.341873 2
2016-01-26 07:45:49.341873 11
2016-01-27 07:45:49.341873 33
Name: warm, dtype: float64, 'yuck': post_timestamp
2016-01-25 07:45:49.341873 -1
2016-01-26 07:45:49.341873 -1
2016-01-27 07:45:49.341873 -7
Name: yuck, dtype: float64}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.