#100DaysOfCode in Python Transcripts
Chapter: Days 58-60: Twitter data analysis with Python
Lecture: Identify the most popular tweets
0:00 And let's see, in particular, what tweets were most popular. And I'm going to first use a list comprehension, which I showed you on Day 16,
0:11 to exclude the retweets. And a retweet is easy to see because it always starts with a RT. Next, let's get the top 10.
0:26 And for that I need to do some sorting. Okay, so how does sorted work? You give it a sequence, which is the list of tweets
0:39 and we use the key argument that can take a function or callable and we give it a lambda, which is basically a just a simple function in a one-liner.
0:47 And we give it a tweet, and then it will average of the number of likes and retweets. That's sorts the list of tweets by highest average.
0:56 And if you then do it reversed=True, you get the highest at the top. Alright? Got already with this format.
1:03 So, let's try the for loop to make it nicer. First, I'll do a specify a format, which I will then use for every row. I got a column of five.
1:20 Separator... Another column of five... And the text. You can use f-strings. When I was preparing this notebook, I will still using the older formats,
1:34 so I'm going with that for now. Besides, if you're not on 3.6, you might still need it. I use some nice icons. Then I do a dashed line
1:49 which I can just say dash times 100 and then the loop. For tweet in top 10, I'm going to print, format, format,
2:02 and then I can just fit in those keyboard arguments likes... and just for the fun of it, let's use a return icon instead of the new line. Oops.
2:20 And I have to close this. Look at that. Our first tweet was the launch of our co-tennis platform. And the second one was our Flash course, etc, etc.
2:31 So we have the likes, number of retweets and the text of the tweets. So here you already see the benefits
2:38 of doing a bit of data analysis to explore your data set. And it's not taking that much of code. Once we have the data loaded in, it's fairly easy.