I get df:
task_id name tag
1 foo xyz
1 foo xyz
22 foo aaa
22 foo aaa
22 foo aaa
22 foo bbb
13 bar xyz
13 bar xyz
33 bar aaa
33 bar aaa
So I trying df['tag'].value_count()
and df_test.groupby('name')['tag'].count()
for two reasons:
One I need count each tag
per task
and second total sum of tags on each task
What I want get:
task_id name tag count_tag total_count
1 foo xyz 2 6
1 foo xyz 2 6
22 foo aaa 3 6
22 foo aaa 3 6
22 foo aaa 3 6
22 foo bbb 1 6
13 bar xyz 2 4
13 bar xyz 2 4
33 bar aaa 2 4
33 bar aaa 2 4
for better understanding, in sql to create such a table, I would do something like this:
SELECT
task_id,
name,
count(tag) AS count_tag,
sum(count(tag)) OVER (PARTITION BY name) AS total_count