Q#55: Active users on a messaging application

Here is a table containing information from a P2P messaging application. The table contains send/receive message data for the application’s users. The structure is as follows:

TRY IT YOURSELF

ANSWER

This question tests our ability to wrangle data in Python specifically by using the pandas library.

First, lets import pandas to load in the data using the .read_csv() method with the path and set the date to the index by using the argument index_col.

import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/erood/interviewqs.com_code_snippets/master/Datasets/ddi_message_app_data.csv', index_col=0)

There are many ways to solve this question, but we are going to use a direct approach using the .groupby() method and .unique() function as our summarizing method to return the answer.

df.groupby('sender_id').receiver_id.unique()

With this we see that every user contacted every other user.

--

--