Answered step by step
Verified Expert Solution
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
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 hourStep 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