In the dataframe that I am working with, there are two columns USERID and Activity. I wanted to find value_counts of each unique value in the Activity column concerning each USERID.
This what I have done:
df9=new_df1.groupby('UserID')['Activity'].apply(lambda x:x.value_counts())
Output:
UserID level_1 Activity
0 U100003 CLICK 2
1 U100003 PAGELOAD 1
2 U100005 PAGELOAD 1
3 U100008 CLICK 22
4 U100008 PAGELOAD 20
5 U100009 CLICK 4
6 U100009 PAGELOAD 4
7 U100012 CLICK 14
8 U100012 PAGELOAD 5
9 U100013 PAGELOAD 5
10 U100013 CLICK 3
11 U100014 CLICK 2
12 U100014 PAGELOAD 1
13 U100015 CLICK 8
14 U100015 PAGELOAD 3
15 U100016 PAGELOAD 1
16 U100018 CLICK 16
17 U100018 PAGELOAD 5
18 U100019 CLICK 15
19 U100019 PAGELOAD 5
What I need is for each USERID there should be two columns with the name of 'CLICKS' and 'PAGELOAD' and the values be assigned to those columns concerning each USERID.
USERID Clicks Pageload
U100003 2 1
U100005 Nan 1
U100008 22 20