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)
How to calculate the click-through rate