Created
February 20, 2017 22:18
-
-
Save danromero/c31f62a32553842648c46a4e4f53dfdb to your computer and use it in GitHub Desktop.
Show the distribution of the last 100 Delighted.com NPS responses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib inline | |
import delighted | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
import numpy as np | |
# Add your Delighted API key — https://delighted.com/account/api | |
delighted.api_key = 'INSERT API KEY HERE' | |
x = delighted.SurveyResponse.all(order='desc:updated_at', per_page=100) | |
score_list = [] | |
for item in x: | |
score_list.append(item['score']) | |
df = pd.DataFrame(data=score_list, columns=['scores']) | |
summary_df = df['scores'].value_counts().sort_index(ascending=True) | |
tuple_for_chart = tuple(summary_df.tolist()) | |
nps_colors = ['r', 'r', 'r', 'r', 'r', 'r', 'r', 'b', 'b', 'g', 'g'] | |
nps_range = np.arange(11) | |
width = .95 | |
fig, ax = plt.subplots(figsize=(6, 4)) | |
ax.bar(nps_range, tuple_for_chart, width, color=nps_colors) | |
ax.set_ylabel('Responses') | |
ax.set_xlabel('Scores') | |
ax.set_title('NPS Score Distribution') | |
ax.set_xticks(nps_range + width / 2) | |
ax.set_xticklabels(nps_range) | |
plt.xlim([-1,12]) | |
plt.ylim([0,50]) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment