Skip to content

Instantly share code, notes, and snippets.

@malomarrec
Created May 30, 2023 13:09
Show Gist options
  • Save malomarrec/f23d24acf42589219ce994a15dd3a988 to your computer and use it in GitHub Desktop.
Save malomarrec/f23d24acf42589219ce994a15dd3a988 to your computer and use it in GitHub Desktop.
// Setup: pip3 install pandas matplotlib wordcloud
import pandas as pd
import matplotlib.pyplot as plt
from wordcloud import WordCloud
import re
def replace_substring(test_str, s1, s2):
# Replacing all occurrences of substring s1 with s2
test_str = re.sub(s1, s2, test_str)
return test_str
# Helpers
def filter_words(text):
"""Filter words that are noisy, such as 'code' """
words = ['code', 'feature', 'base', 'change', 'one',
'make', 'please', 'use', 'Cody', ' s ', 'ability']
for word in words:
text = replace_substring(text, word, '')
return text
# Data processing
df = pd.read_csv("~/data/superhuman-survey/data/survey-export-2023-05-30.csv")
df.columns = ['timestamp', 'email', 'job_title', 'cody_distribution',
'what_if', 'people_type', 'main_benefit', 'improve']
for i, col in enumerate(['job_title', 'cody_distribution', 'what_if', 'people_type', 'main_benefit', 'improve']):
mask = (df['what_if'] == 'Very disappointed') | (
df['what_if'] == 'Somewhat disappointed')
# mask = (df['what_if'] == 'Not disappointed')
text = " ".join(filter_words(feedback) for feedback in df[mask][col])
word_cloud = WordCloud(
collocations=False, background_color='white').generate(text)
plt.subplot(3, 2, i+1)
plt.title(col)
plt.imshow(word_cloud, interpolation='bilinear')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment