← 2023 questions

2023 / INSTAGRAM / QUESTION 6

Engagement rankings

Try the question in your own editor, then check your output below.

THE QUESTION

A social media star named Finnick wants to examine his Instagram account to determine which photos have received the most likes and comments. He wants to learn which postings receive the most likes, comments, and interactions. He keeps track of the likes and comments received on his Instagram postings. To read this data and determine the interaction for each article, he wants to create a Python programme.

He wants to apply the algorithm below to determine engagement:

Engagement is calculated as (likes + comments) / the number of followers.

To see which posts are performing the best, he also wants to display the posts in descending order of interaction.

Task:

Write a Python program that can read in the list of Instagram posts, calculate the engagement for each post using the formula provided, and display the posts in descending order of engagement.

Your program should have the following functionalities:

Read the list of Instagram posts from a CSV file:

Instagram posts CSV

The original input file could not be recovered. This question needs that dataset to reproduce the original exercise.

The CSV file will have two columns: "likes" and "comments". Each row will correspond to one post.

Store the number of followers in a variable called num_followers.

Calculate the engagement for each post using the formula provided and store it in an engagement list.

Display the posts in descending order of engagement and the number of likes, comments, and engagement.

Question by Aaleyah. Source: Girls In Code SEA — Behind the Screens, 2023, slide 20.

PRACTICE CHECK

Try your answer.

The original spreadsheet is unavailable. These labelled practice rows replace it only for this check.

Run your program in your own editor, then paste its output below. This checks the stated output or checkpoint; it does not assess your full program. Practice attempts do not affect competition scores.

New practice CSV rows (post, likes, comments): A,80,20; B,150,50; C,30,20. num_followers = 1000. Enter post IDs in descending engagement order.

Enter the three engagement rates in the same descending order.

Reveal worked answer

Post order

["B", "A", "C"]

Engagement rates

[0.2, 0.1, 0.05]

B: (150+50)/1000 = 0.2; A: 0.1; C: 0.05.