Question: In Python 2.7 CrimeReport is Available at https://pastebin.com/UZVftJYH Task 7: Data Preprocessing Read the tweets from the file CrimeReport.txt and print the id for each
In Python 2.7
CrimeReport is Available at https://pastebin.com/UZVftJYH

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 j , %a %b %d 3H:%M%S +0000 %Y') #converts the string format of a date time to the datetime object lambda item: , created-at ,] , sorted-tweets = sorted (tweets, key datetime. datetime. strptime (item ,%a %b %d 3H:XM:%S +0000 %Y')) # sorted tweets based on time. f = open ( ' output . txt ' , 'w' ) for tweet in sorted-tweets-5: ]: f. write (json. dumps(tweet) +'\') f. close () Note, when you copy and paste the code above, please be careful with the proper indentation and quotation mark
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
