Introduction to pandas for marketing

Analyzing Marketing Campaigns with pandas

Jill Rosok

Data Scientist

What does a data scientist on a marketing team do?

shutterstock_299886734.jpg

  • Analyzing marketing campaign performance

  • Attributing credit for conversions to marketing channels

  • A/B testing

Analyzing Marketing Campaigns with pandas

What is pandas, again?

  • Provides table-like data structures that are easy to use in analysis

pandas-logo

  • Allows for easy importing and exporting of a variety of common formats (i.e., CSV, TSV, Stata)

  • Enables manipulation such as joining other datasets, grouping by and aggregating columns, and taking subsets of dataset columns and rows.

Analyzing Marketing Campaigns with pandas

Importing data using pandas

import pandas as pd

marketing = pd.read_csv('marketing.csv')
Analyzing Marketing Campaigns with pandas

Inspecting data

print(marketing.head())
      user_id date_served    channel          variant  conv  \
0  a100000029  2018-01-01  House Ads  personalization  True   
1  a100000030  2018-01-01  House Ads  personalization  True   
2  a100000031  2018-01-01  House Ads  personalization  True   
3  a100000032  2018-01-01  House Ads  personalization  True   
4  a100000033  2018-01-01  House Ads  personalization  True   

  language_displayed language_preferred    age_group  
0            English            English   0-18 years  
1            English            English  19-24 years  
2            English            English  24-30 years  
3            English            English  30-36 years  
4            English            English  36-45 years
Analyzing Marketing Campaigns with pandas

Summary statistics

print(marketing.describe())
           user_id date_served    channel  variant   conv    \
count         9882        9881       9882     9882   9882 
unique        7253          31          5        2      2 
top     a100000882  2018-01-15  House Ads  control  False 
freq             6         782       4682     4986   8883 

           language_displayed language_preferred     age_group
count                    9882               9882          9882
unique                      4                  4             7
top                   English            English   19-24 years
freq                     9695               9177          1650
Analyzing Marketing Campaigns with pandas

Missing values & data types

print(marketing.info())
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 9996 entries, 0 to 9995
Data columns (total 12 columns):
#   Column                Non-Null Count  Dtype 
    ------                --------------  ----- 
0   user_id               9996 non-null   object
1   date_served           9980 non-null   object
    ...
9   date_subscribed       1815 non-null   object
10  date_canceled         568 non-null    object
11  subscribing_channel   1815 non-null   object
12  is_retained           1815 non-null   object
    dtypes: object(12)
memory usage: 937.2+ KB
Analyzing Marketing Campaigns with pandas

Let's Practice!

Analyzing Marketing Campaigns with pandas

Preparing Video For Download...