Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Ehs 2.0 Revolutionizing The Future Of Safety With Digital Technology

Authors: Tony Mudd

1st Edition

B0CN69B3HW, 979-8867463663

More Books

Students also viewed these Databases questions

Question

Question in Chemical Engineering Please give Correct Answer 1 3 5 .

Answered: 1 week ago

Question

11. Are your speaking notes helpful and effective?

Answered: 1 week ago

Question

The Goals of Informative Speaking Topics for Informative

Answered: 1 week ago