Skip to content

Instantly share code, notes, and snippets.

@stestagg
Created March 28, 2018 14:25
Show Gist options
  • Save stestagg/7658d663278d6f7becb7ca21c34e07c6 to your computer and use it in GitHub Desktop.
Save stestagg/7658d663278d6f7becb7ca21c34e07c6 to your computer and use it in GitHub Desktop.
# Find the matching rows (where the first column is True)
word_rows = one_grams[IS_WORD_COL]
# Create an empty array to hold the per-year % values
word_counts = np.zeros(last_year+1)
# Iterate over each matching row (for a matching word, there should just be 1,000s of rows)
for _, year, count in one_grams[word_rows]:
# Set the relevant word_counts row to the calculated value
word_counts[year] += (100*count) / year_totals[year]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment