Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate the click-through rate

Here is an example, I have this data;

    datetime    keyword COUNT
0   2016-01-05  a_click 100
1   2016-01-05  a_pv    200
2   2016-01-05  b_pv    150
3   2016-01-05  b_click 90
4   2016-01-05  c_pv    120
5   2016-01-05  c_click 90

and I'd like to transform it to this data

    datetime    keyword ctr
0   2016-01-05  a       0.5
1   2016-01-05  b       0.6
2   2016-01-05  c       0.75

I can transform data with dirty codes but I'd like to do it the elegant way.

like image 270
samurait Avatar asked Jan 05 '16 01:01

samurait


People also ask

How is click-through rate calculated email?

Email click through rate is calculated by the number of subscribers that have clicked on at least one link in your email marketing campaign. To calculate email click through rate, take the number of people that have clicked on your email campaign and divide that with the number of emails you have sent.

How do you calculate CTR in Excel?

Calculating Click Through Rate or CTR in Microsoft Excel There is actually one more step in Excel. You can either edit the formula to be (CELL1/Cell2*100) OR just modify the cell formatting to be a “percentage.” You can also play with the decimals if you want more or less accuracy.

Is 5% a good click-through rate?

So, CTR is a ratio displayed as a percentage. The average CTR for Google Ads should fall somewhere between 3 and 5% – most marketers consider that good.


1 Answers

You could:

df['action'] = df.keyword.str.split('_').str.get(-1)
df['keyword'] = df.keyword.str.split('_').str.get(0)
df = df.set_index(['datetime', 'keyword', 'action']).unstack().loc[:, 'COUNT']
df['ctr'] = df.click.div(df.pv)


action              click   pv   ctr
datetime   keyword                  
2016-01-05 a          100  200  0.50
           b           90  150  0.60
           c           90  120  0.75
like image 187
Stefan Avatar answered Oct 08 '22 22:10

Stefan