Published on

Making Sense of Your Instagram Data with Python

Authors

I've been active on Instagram for a few years now, and ever since I saw the option to download the data Instagram generates for my profile, I jumped right in to check it out.

Step 1: Request your data from Instagram

You can find this in the app under Settings > Account > Download data.

Requesting your data from Instagram

Step 2: Convert your data into something useful

import json

import pandas as pd

# Reading the json as a dict
with open('isacarracine_20210123_part_1/likes.json') as json_data:
    data = json.load(json_data)

# Create a pandas data frame with likes
likes_df = pd.DataFrame(data, columns=['media_likes'])
# Column 0 has date data so we place it on a separate field
likes_df['date'] = likes_df['media_likes'].apply(lambda row: row[0])
# Column 1 has username data so we place it on a separate field
likes_df['username'] = likes_df['media_likes'].apply(lambda row: row[1])
# Clean up the data frame so we only have 2 columns
likes_df = likes_df.drop(['media_likes'], axis=1)

Step 3: Make sense of your data

Now we would like to know who our BFF is.

# Check out whose posts we've liked the most ever
summarized_df = likes_df.groupby('username').count()
print(summarized_df.sort_values('date', ascending=False))

# Will show you a neat list like the following in your terminal
# username
# user21         226
# user231        145
# user354        106
# user45         105
# user453         95

With those three simple steps you're able to analyze your own data and look for patterns.

Stay tuned for part 2, where I'll show you what sorts of things we can figure out from your Instagram data.

Originally published on isacarracine.com in August 2021.

Get the next one

Posts on data, analytics and the judgment calls that decide whether a model gets trusted.

ShareLinkedInXReddit