CSC 221: Introduction to Programming
Fall 2018

HW6: Lists and Data


For this assignment, you will write two functions that access and analyze a file of structured tweet data. You may assume that the file contains one tweet per line, with seven comma-separated values per tweet. The first line of the file contains comma-separated headings that identify each of the seven values. For example,

text,date (GMT),time (GMT),day (GMT),retweet_count,favorite_count,is_retweet how about those bluejays,2018-10-22,1:49:00,Mon,120,203,FALSE I'm Mr. Meeseeks - look at me,2018-10-21,22:48:00,Sun,2150,1024,TRUE my first tweet :-),2018-10-21,19:26:00,Sun,22931,92245,FALSE . . .

The file TrumpTweetsMeta.csv contains all of Donald Trump's tweets (through October 21, 2018) with corresponding metadata.


PART 1: all_hour_stats (50%)

In class, we wrote a function named all_day_stats that had a single input, a structured list of tweet data, and which displayed tweet counts for each day of the week. You are to write a function named all_hour_stats that similarly displays tweet counts for every hour of the day (ranging from 0 to 23). For example:

Note that the output should appear as above, with the data aligned in columns and a heading a the top. Also, recall that times in the tweet file are in Greenwich Mean Time (GMT). You should adjust those times to the Eastern time zone (five hours earlier) when collecting your statistics.


PART 2: year_splits (50%)

In class, we wrote a function named am_pm_counts that had a single input, a structured list of tweet data, and which displayed tweet counts from the a.m. and p.m. You are to write a function named year_splits that has an additional input, a date in the format "YYYY-MM-DD", and similarly displays tweet counts for the year split by that date. That is, it should display the number of tweets from before that date (in the same year) and also the number of tweets on or after that date (in the same year). For example:

The output should be in the format shown above. The following function, which determines whether one date comes before another, may prove useful in completing this task.


Save your functions in a file named lastnameTweets.py, where lastame is your last name. Your file should have a comment block at the top that includes your name and a brief description of the file, and each function should have a doc string that describes its behavior. Be careful to name the two functions exactly as specified, and feel free to implement additional helper functions as needed.