'I'm getting an index error when I use index to access my list

I've started using snscrape to get twitter data for my project. I'm outputting the data in a list format and using pandas to properly visualize it. since the engagement data is not constant and consistenly updates. I'm trying to use, a for loop and an if statement to compare and update it if needed but when I try to use index to access the specific properties in the list like:

like, retweet and reply count

It gives me an index error.

Script

#get data

import snscrape.modules.twitter as sntwitter
import pandas as pd 

tweets_list1 = []
for i, tweet in enumerate(sntwitter.TwitterSearchScraper('from:TheHoopCentral').get_items()):
    if i > 100:
        break
    tweets_list1.append([tweet.content, tweet.id,tweet.likeCount, tweet.retweetCount, tweet.replyCount, tweet.user.username])
    print(tweets_list1)

tweets_df1 = pd.DataFrame(tweets_list1, columns=['text', 'Tweet id','LikeCount', 'RetweetCount', 'ReplyCount', 'Username'])
tweets_df1.head()

#updating engagement

tweets_list1 = []
for i, tweet in enumerate(sntwitter.TwitterSearchScraper('TheHoopCentral').get_items()):
    if tweet.likeCount > tweets_list1[2]:
        tweets_list1.insert(2, tweet.likeCount)
    elif i > 100:
        break

Error

IndexError                                Traceback (most recent call last)
<ipython-input-26-c679f6d5eecc> in <module>
      3 tweets_list1 = []
      4 for i, tweet in enumerate(sntwitter.TwitterSearchScraper('TheHoopCentral').get_items()):
----> 5     if tweet.likeCount > tweets_list1[2]:
      6         tweets_list1.insert(2, tweet.likeCount)
      7     elif i > 100:

IndexError: list index out of range


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source