AnalystPath

Facebook Heart-Reacted Posts

PandasMediumMid levelMeta~15 min

Problem

**[Asked at Meta]**

For each post, count the number of **distinct users who reacted with a heart**.
Return all posts sorted by heart count descending.

Return `title` and `heart_count`.

Input data

Example rows — the live problem includes the full dataset.

reactions
reaction_iduser_idpost_idreaction_type
11011heart
21021heart
31031like
41012heart
51022laugh
posts
post_idauthor_idtitle
1201Post One
2202Post Two
3201Post Three

Expected output

Your answer should return 3 rows with the columns title, heart_count.

Starter code (Pandas (Python))

import pandas as pd

def heart_posts(reactions: pd.DataFrame, posts: pd.DataFrame) -> pd.DataFrame:
    # Your code here
    return reactions

Solve this Pandas question free

Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related Pandas questions