Compare major tech Instagram page's with instascrape
Tags: python, showdev, datascience, contributorswanted
Published: 2020-11-12 07:47:35

In this blog post, I'm going to compare some of the largest tech company's Instagram page's using my open source Python library _instascrape_! We'll be exploring their respective engagements, followers, amount of posts, etc. :raised_hands:

{% github https://github.com/chris-greening/instascrape %}

The companies we'll be comparing for this exercise are 
* [Google](https://www.instagram.com/google/)
* [Apple](https://www.instagram.com/apple/)
* [IBM](https://www.instagram.com/ibm/)
* [Facebook](https://www.instagram.com/facebook/)
* [Microsoft](https://www.instagram.com/microsoft/)
* [Adobe](https://www.instagram.com/adobe/)
* [Oracle](https://www.instagram.com/oracle/)

# Scraping the data 

First, let's start by getting a `list` of their usernames:

```python
companies = ["google", "apple", "ibm", "facebook", "microsoft", "adobe", "oracle"]
```

Now, scraping our data is as easy as 
```python
from instascrape import Profile 
profiles = [Profile(username) for username in companies]
for prof in profiles: 
    prof.scrape()
```

And that's it! We just scraped 364 data points from 7 profiles with just a few lines of code, let's use the `to_dict` method to get a `list` of `dict`'s that can be passed into a [`pandas.DataFrame`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html) for expressive and powerful data analysis. 
```python
import pandas as pd 
data = [prof.to_dict() for prof in profiles]
df = pd.DataFrame(data)
```

# Exploring our data 

First, let's start by comparing how many followers each page has using a [matplotlib](https://matplotlib.org/) bar plot: 

```python
import matplotlib.pyplot as plt 
plt.style.use("seaborn-darkgrid")
plt.bar(df["username"], df["followers"]) 
```

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/do9h7s5kufla4ng4f0hs.png)

We can immediately see that Apple clearly has the most followers and surprisingly, Facebook doesn't have as many as one might expect.

Now let's see who has the most amount of posts:

```python
import matplotlib.pyplot as plt 
plt.style.use("seaborn-darkgrid")
plt.bar(df["username"], df["posts"]) 
```

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/h4i8nznvyc6xpup4s2vh.png)

Finally, we're going to examine each page's engagement as a function of time and see how the different pages are doing 

(_NOTE:_ some of the specifics in the code are skipped so we can focus on what's important; additionally Apple will not be pictured as their data is significantly larger)

```python
for prof in profiles:
    posts = prof.get_recent_posts()     #gets the 12 most recent posts
    posts_data = [post.to_dict() for post in posts]
    post_df = pd.DataFrame(posts_data)
    plt.plot(post_df.upload_date, post_df.likes, label=prof.username)
```

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/dvn8lcyj12vmct2nk29q.png)

Some interesting things we can see right off the bat are:
* Oracle _barely_ gets any likes 
* Surprisingly neither does Facebook
* Adobe, Google, and Microsoft post relatively frequently 
* IBM hasn't posted in almost two weeks 
* Microsoft gets the most likes on average on their posts 

# Conclusion 

And that's pretty much it! This is just a small taste of what _instascrape_ can accomplish and it's up to you with how you use it so get out there and start exploring that data! 

If you like what you read, check out some of my other posts :smile: 

{% link https://dev.to/chrisgreening/scraping-25-000-data-points-from-joe-biden-s-instagram-using-instascrape-1026 %}
{% link https://dev.to/chrisgreening/downloading-an-instagram-profile-s-recent-photos-using-python-25b2 %}

Also, check out the official repository and drop it a star :star: or contribute! 

{% github https://github.com/chris-greening/instascrape %}