Knowee
Questions
Features
Study Tools

Search for those tweets that contain either the word "COVID" or "pandemic". Save the output to a new dataframe called covid_tweets.Calculate the percentage (2 decimal places) of tweets that contain either the word "COVID" or "pandemic" and save this as "perc_covid". Use this value to create a sentence that says: "(perc_covid) % of tweets from Scott Morrison were about COVID or the pandemic". Save this sentence as a variable called answer.

Question

Search for those tweets that contain either the word "COVID" or "pandemic". Save the output to a new dataframe called covid_tweets.Calculate the percentage (2 decimal places) of tweets that contain either the word "COVID" or "pandemic" and save this as "perc_covid". Use this value to create a sentence that says: "(perc_covid) % of tweets from Scott Morrison were about COVID or the pandemic". Save this sentence as a variable called answer.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a Python script that accomplishes the tasks you've outlined:

# Search for tweets that contain either the word "COVID" or "pandemic"
covid_tweets = tweet_df[tweet_df['full_text'].str.contains('COVID|pandemic', case=False, na=False)]

# Calculate the percentage of tweets that contain either the word "COVID" or "pandemic"
perc_covid = round((len(covid_tweets) / len(tweet_df)) * 100, 2)

# Create a sentence that says: "(perc_covid) % of tweets from Scott Morrison were about COVID or the pandemic"
answer = f"{perc_covid} % of tweets from Scott Morrison were about COVID or the pandemic"

This script first creates a new DataFrame 'covid_tweets' that contains only the tweets from 'tweet_df' that contain either the word "COVID" or "pandemic". It then calculates the percentage of tweets that contain either of these words by dividing the number of tweets in 'covid_tweets' by the total number of tweets in 'tweet_df', multiplying by 100, and rounding to two decimal places. Finally, it creates a string 'answer' that contains this percentage and the specified sentence.

This problem has been solved

Similar Questions

Write Python code to count the frequency of hashtags in a twitter feed.Your code assumes a twitter feed variable tweets exists, which is a list of strings containing tweets. Each element of this list is a single tweet, stored as a string. For example, tweets may look like:tweets = ["Happy #IlliniFriday!", "It is a pretty campus, isn't it, #illini?", "Diving into the last weekend of winter break like... #ILLINI #JoinTheFight", "Are you wearing your Orange and Blue today, #Illini Nation?"]Your code should produce a sorted list of tuples stored in hashtag_counts, where each tuple looks like (hashtag, count), hashtag is a string and count is an integer. The list should be sorted by count in descending order, and if there are hashtags with identical counts, these should be sorted alphabetically, in ascending order, by hashtag.From the above example, our unsorted hashtag_counts might look like:[('#illini', 2), ('#jointhefight', 1), ('#illinifriday!', 1), ('#illini?', 1)]The hashtag_counts sorted by the above specifications will look like:[('#illini', 2), ('#illini?', 1), ('#illinifriday!', 1), ('#jointhefight', 1)]You may use str.split() to split each tweet into a list of words. A hashtag is any word that starts with a hash mark (#). (That means that the hash mark # should be included in the hashtag value above.)Steps/Hints:Preprocessing: You will need to convert each hashtag to lower case before you count it. For example, for this question #UIUC and #Uiuc add to the count of same hashtag (#uiuc).Do not further process the tweets or hashtags beyond using .split(), such as attempting to remove punctuation. While in the 'real world' you would absolutely do this, in this problem the autograder will be unhappy with you if you do.And if using .split(), do not pass any arguments (when no arguments are added then every kind of whitespace will be considered).You may find it helpful to use an intermediate data structure for this problem to count the frequency of each hastag.If you aren't sure how to sort or convert to lowercase, you may find Python docs how to sort and Python docs for string methods useful.

String AnalysisYou are given a string that represents an email address: "My e-mail: [email protected]". Your task is to analyze the composition of the characters in the string and determine the percentage of uppercase letters, lowercase letters, digits, and other characters such as symbols (#$., etc).To accomplish this, you need to break down the string and calculate the percentage for each category. The results are as follows:Uppercase letters: 7.5%Lowercase letters: 65%Digits: 7.5%Other characters (symbols): 20%Important Note: Ensure that you save your solution before progressing to the next question and before submitting your answer.Exercise-1Input :[email protected] :5.263%78.947%5.263%10.526%Exercise-2Input:[email protected]:4.545%63.636%18.182%13.636%

String AnalysisYou are given a string that represents an email address: "My e-mail: [email protected]". Your task is to analyze the composition of the characters in the string and determine the percentage of uppercase letters, lowercase letters, digits, and other characters such as symbols (#$., etc).To accomplish this, you need to break down the string and calculate the percentage for each category. The results are as follows:Uppercase letters: 7.5%Lowercase letters: 65%Digits: 7.5%Other characters (symbols): 20%Important Note: Ensure that you save your solution before progressing to the next question and before submitting your answer.

Using the date column created in Question 3A, write code to analyse the yearly change (if any) of the number of Scott Morrison favorite_count, which is the number of people who liked each tweet.You should group your dataframe by date and calculate the median of the number of people who liked each tweet. Save this grouped dataframe as a new dataframe called "grouped".Plot the number of people who liked each tweet versus date.PLEASE LEAVE THE COMMENT ### edTest(test_q3b) ### in the code box below for auto-marking.HintsImport the required library/librariesRemember to properly label your axisYour plot should look like this:

Using the date column created in Question 3A, write code to analyse the yearly change (if any) of the number of Scott Morrison favorite_count, which is the number of people who liked each tweet.You should group your dataframe by date and calculate the median of the number of people who liked each tweet. Save this grouped dataframe as a new dataframe called "grouped".Plot the number of people who liked each tweet versus date.PLEASE LEAVE THE COMMENT ### edTest(test_q3b) ### in the code box below for auto-marking.HintsImport the required library/librariesRemember to properly label your axis

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.