Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in python 2.7 Write a def task9() function for task 9 file operations CRIMEPORT.TXT IS https://pastebin.com/PgGWn5BC Task 8: Data Preprocessing: tweets filtering INPUT: CrimeReport.txt OUTPUT:

in python 2.7

Write a def task9() function for task 9 file operations

CRIMEPORT.TXT IS https://pastebin.com/PgGWn5BC

image text in transcribed

Task 8: Data Preprocessing: tweets filtering INPUT: "CrimeReport.txt" OUTPUT: a file " task8.data" that stores the 10 most recent tweets kkk*kkkkakkk*kakkkk**kkkk*kkkkakk* Suggestions tweet l'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 ne in open.readlines ): tweet = json . loads ( line ) tweets.append (tweet) #datetime, datetime, strptime (item[ , created-at'] , ,%a %b % YH:%M%S +0000 %Y') #converts the string format of a date time to the datetime object sorted-tweets = sorted (tweets, key = lambda item: datetime. datetinne, strptime (item [ , created-at'] , ,%a Yb %d 9 H:%M:%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 mar Task 9: File operations Using task 8 complete task 9 INPUT:CrimeReport.txt: in this file, each line is a raw tweet json format output-folder: where new results will be stored REQUIREMENT: read tweets and separate these tweets in to groups based on the specific hours (Mon-Day- Year-Hour). The tweets related to a specific hour will be stored in a separate file in the folder"task9-output" with the file name "Mon-Day-Year-Hour.txt" OUTPUT: new files generated and stored in the folder "task9-output", in which each file stores the tweets corresponding to a specific hour Task 8: Data Preprocessing: tweets filtering INPUT: "CrimeReport.txt" OUTPUT: a file " task8.data" that stores the 10 most recent tweets kkk*kkkkakkk*kakkkk**kkkk*kkkkakk* Suggestions tweet l'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 ne in open.readlines ): tweet = json . loads ( line ) tweets.append (tweet) #datetime, datetime, strptime (item[ , created-at'] , ,%a %b % YH:%M%S +0000 %Y') #converts the string format of a date time to the datetime object sorted-tweets = sorted (tweets, key = lambda item: datetime. datetinne, strptime (item [ , created-at'] , ,%a Yb %d 9 H:%M:%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 mar Task 9: File operations Using task 8 complete task 9 INPUT:CrimeReport.txt: in this file, each line is a raw tweet json format output-folder: where new results will be stored REQUIREMENT: read tweets and separate these tweets in to groups based on the specific hours (Mon-Day- Year-Hour). The tweets related to a specific hour will be stored in a separate file in the folder"task9-output" with the file name "Mon-Day-Year-Hour.txt" OUTPUT: new files generated and stored in the folder "task9-output", in which each file stores the tweets corresponding to a specific hour

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_2

Step: 3

blur-text-image_3

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

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions