posts has columns post_id, post_date (datetime) and keywords.
views has columns post_id and viewer_id. A post is spam when its
keywords string contains "spam".
For each day on which at least one post was viewed, compute the percentage of
views that landed on a spam post. Return a DataFrame with columns day (the
date as a "YYYY-MM-DD" string) and spam_pct, rounded to 2 decimal places,
sorted by day with the index renumbered from 0.
Posts nobody viewed do not appear, since a day with no views has no percentage.
Input
posts =
post_id post_date keywords
0 1 2022-04-01 sale spam deal
1 2 2022-04-01 holiday
2 3 2022-04-02 spam
views =
post_id viewer_id
0 1 9
1 1 8
2 2 7
3 3 6
Output
day spam_pct
0 2022-04-01 66.67
1 2022-04-02 100.00