Skip to content

Instantly share code, notes, and snippets.

@dzakyputra
Created June 17, 2020 00:40
Show Gist options
  • Save dzakyputra/330817fdd67a5ec5c4c6700593603179 to your computer and use it in GitHub Desktop.
Save dzakyputra/330817fdd67a5ec5c4c6700593603179 to your computer and use it in GitHub Desktop.
query = """
SELECT
complete.offer_type,
complete.complete_without_view_income,
complete_view.complete_with_view_income
FROM
(SELECT
offer_type,
AVG(income) complete_without_view_income
FROM
complete_data
WHERE
viewed = 0
AND completed = 1
GROUP BY
offer_type) complete
JOIN
(SELECT
offer_type,
AVG(income) complete_with_view_income
FROM
complete_data
WHERE
viewed = 1
AND completed = 1
GROUP BY
offer_type) complete_view ON complete.offer_type = complete_view.offer_type
"""
income_differences = pdsql.sqldf(query)
# Start the visualization
plt.figure(figsize=(12,5))
sns.barplot(data=income_differences.melt(id_vars='offer_type'),
y='offer_type',
x='value',
hue='variable',
palette=sns.color_palette("ch:2.5,-.2,dark=.05"))
plt.legend(loc="upper left", bbox_to_anchor=(1,1.02))
plt.title('Average Income per Completeness and Offer Type')
plt.xlabel('average income ($)')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment