Skip to content

Instantly share code, notes, and snippets.

@foohm71
Created September 12, 2020 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foohm71/9a6426358cd7ce34503743d7a5ae68a2 to your computer and use it in GitHub Desktop.
Save foohm71/9a6426358cd7ce34503743d7a5ae68a2 to your computer and use it in GitHub Desktop.
Common functions
def make_autopct(values):
def my_autopct(pct):
total = sum(values)
val = int(round(pct*total/100.0))
return '{p:.1f}% ({v:d})'.format(p=pct,v=val)
return my_autopct
def plotPieChart(column):
freq_count = Counter(df[column])
fig, ax = plt.subplots(figsize=(15, 7), subplot_kw=dict(aspect="equal"))
patches, texts, autotexts = ax.pie(freq_count.values(), labels=freq_count.keys(), autopct=make_autopct(freq_count.values()), textprops=dict(color="w", size=12, weight='bold'))
ax.legend(patches, freq_count.keys(), loc="upper left")
ax.set_title(column)
plt.show()
def plotHorzBar(column):
data = df[column]
count = {}
for d in data:
words = d.split(";")
for w in words:
if w in count.keys():
count[w] = count[w] + 1
else:
count[w] = 1
y_pos = np.arange(len(count.keys()))
plt.barh(y_pos,count.values())
plt.yticks(y_pos, count.keys())
plt.show()
def plotBar(column):
data = df[column]
data = data.dropna()
count = {1:0,2:0,3:0,4:0,5:0}
for d in data:
count[d] = count[d] + 1
y_pos = range(1,6)
plt.bar(y_pos,count.values())
plt.yticks(y_pos, count.keys())
plt.title("1 - highly disagree, 5 - highly agree")
plt.show()
def plotWordCloud(column):
data = df[column]
data = data.dropna()
text = data.to_string()
wordcloud = WordCloud(width = 900, height = 500, random_state=1, background_color='salmon', colormap='Pastel1', collocations=False, stopwords = STOPWORDS).generate(text)
plt.figure(figsize=(20, 15))
# Display image
plt.imshow(wordcloud)
# No axis details
plt.axis("off");
def summarizeFeedback(column):
data = df[column]
data = data.dropna()
text = data.to_string()
summ_per = summarize(text, ratio = 0.30)
summ = Markdown('<h3>{}</h3>'.format(summ_per))
return summ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment