π² Casino Analytics Dashboard - Part 7
Plotting Retention Heatmap
I rewrote the cohort analysis β in Python β using Pandas, Numpy, and the simulated weekly dataset in .csv format. The choice to select Python to continue with the script to simplify the process, and the libraries can help a lot.
Main Goals of the day:
- Replicate cohort analysis in Python
- Generate Retention Heatmap (Day 0 to Day 6)
- Save output as CSV + PNG for Tableau later
Step by Step
π Step 1: Merged first_deposit with full session data
π Step 2: Calculated day_diff = (session_date - cohort_date).days
π Step 3: Filtered to day_diff <= 6
π Step 4: Used groupby(['cohort_date', 'day_diff']) β counted unique players
π Step 5: Pivot β normalized by cohort size β got retention %
π Step 6: Plotted heatmap β saved as intra_week_cohort_heatmap.png
Challenges / Insights
I did it in a few lines of Python, comparing the same script in SQL.
And I understand it better than if Iβd just run a query.
The script shows immediately the result:
- Players who deposited on Sep 4-7 β 75% average retention till Day 6
- Players who deposited on Sep 5β7 β 63% average
Why?
Because Sep 5-7 = weekend.
Sep 4β7 = time to prepare for the weekend.
Just an example for the importance of timing strategy for a marketing campaign.
Code Snippet Final
1
2
3
4
cohort_retention = cohort_pivot.divide(cohort_size, axis=0).round(3) * 100
sns.heatmap(cohort_retention, annot=True, fmt='.0f', cmap='Blues')
plt.savefig('reports/intra_week_cohort_heatmap.png')
</pre>
Next Step
π Tableau report β Time to visualize the results.