Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Python 2.7. CrimeReport is ther https://pastebin.com/UjwMSmUZ Task 7: Data Preprocessing Read the tweets from the file CrimeReport.txt and print the id for each tweet.
In Python 2.7. CrimeReport is ther https://pastebin.com/UjwMSmUZ
Task 7: Data Preprocessing Read the tweets from the file CrimeReport.txt" and print the id for each tweet. Here are some functions that you will use in the task: open().readlines(), tweet -json.loads(), print tweet.keys), you will know the keys of tweet dictionary object, then you can find which key relates to tweet id, and you can then retrieve the id of this specific tweet Task 8: Data Preprocessing: tweets filtering INPUT: "CrimeReport.txt" OUTPUT: a file "task8.data" that stores the 10 most recent tweets Suggestions tweet|'created - at'] gives the created time of this tweet. Rank tweets based on the time from the earliest to the most recent. Then we can identify the 10 most recent tweets. Some example lines that are not directly runnable import datetime tweets = for line in open (). readlines ): tweet - json. loads (line) tweets.append (tweet) #datetime. datetime. strptime( item[ , created-at ,] , %a %b %d :%M:%S +0000 %Y') #converts the string format of a date time to the datetime object sorted-tweets = sorted (tweets, key= lambda item: %a %b %d %H:%M%S +0000 %Y')) # sorted tweets based on time. for tweet in sorted-tweets[-5:J: f. close( Note, when you copy and paste the code above, please be careful with the proper indentation and quotation datetime. datetime. strptime( item [ , created-atj , open ( ' output . txt ' , f. write (json . dumps (tweet)') f 'w' ) markStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started