Question: Python via PyCharm - - Starter code: # Below is data from the physical activity study. physical_activity_data = [eqc244, Run, qqa640, run, Walk, cwq565, Jog,

Python via PyCharm

-

Python via PyCharm - - Starter code: # Below is data fromthe physical activity study. physical_activity_data = ["eqc244, Run", "qqa640, run, Walk", "cwq565,Jog, bike", "zpr647, Bike, Walk", "jvu311, walk, Workout", "jnm492, Run", "gcs800, Run",-

Starter code:

# Below is data from the physical activity study. physical_activity_data = ["eqc244, Run", "qqa640, run, Walk", "cwq565, Jog, bike", "zpr647, Bike, Walk", "jvu311, walk, Workout", "jnm492, Run", "gcs800, Run", "dvd058, jog, Bike", "krg839, jog, Run", "fud109, bike, jog", "tcw030, Run, walk", "zvz690, walk, workout", "nst915, Walk", "rgi867, walk, Bike", "tpq635, bike", "gmp012, Jog, Bike", "aux704, walk, jog", "zsa777, walk, run, baseball", "ghw843, Walk", "lzn822, Bike", "gca402, bike, Walk", "klq707, Run, run", "xji280, Walk, Jog", "pca913, Bike, bike, Lift", "yum565, Walk, Jog", "ugm113, Run", "pba365, Walk", "cnd946, Jog", "idk407, Jog, Run", "auj402, jog, run"]

Purpose: To practice using methods in the string object. Practice with mixing loops and conditionals, and basic list manipulation. Degree of Difficulty: Moderate. Data collection generally refers to the process of gathering and measuring data about specific things. The measurements and results derived from data collection can be quite powerful and help researchers an- swer important quesitons. Suppose we are helping a research lab at the U of S to analyze data they have collected about student's physical activity. Students were given a survey and asked "What physical activities do you do at least once a week for more than 10 minutes?" Sadly, the records from the data collection came back in individual strings with comma () separators. Ac tivites also have inconsistent capitalization. So we will have to do some data cleaning before we analyze An examble of some of the data can be seen below "eqc244, Run" , a640, run, Walk" , 565, Jog, bike", " zpr647, Bike, Walk", " jvu311, walk, Workout"] We have provided you with a python file called a4q1 starter.py which defines a single list variable physical_activity data which includes all the collected data. Starting with this file, do the following (a) The data isn't well formatted, so let's write a function to clean it up. Write a function called clean_data) that takes one parameter, a list of activity records, and returns a list of strings (activities) For each item in the original list, you will have to do the following Use the string method split) to generate a list of the activites. Here is an example showing the usage of split() animals- ,dog, cat ,pig, goat, # define a string variable new-list animals. split(',,) # split with , , , argument print(new_list) ['dog, , ,cat', 'pig,, ,goat,] # new-list now refers to this list After splitting, use the string method lower ) and strip) to make sure all activities are lower case and don't have leading or trailing spaces. Add the clean activities to a new list that will be returned by your clean_data() function. If you ran your clean_data() function on the example data from earlier, it should return a list like this: ['run', 'run', walk', 'jog', 'bike' bike', walk', 'walk', 'workout'] Note that this new list does not include the NSIDs from the previous list. We are not using them for our analysis so they can be ignored. Be sure that you don't add them to the return list! (b) Write a function called count_activites) that takes two parameters: a string activity containing a single activity, and a list of strings activity_list. The function must return the number of occurrences of activity in activity_list. If we passed in the list from above, and the argument run', the function would return 2 (c) Write a function called unique_activitiesO with one parameter called activity_list which is a list of strings where each string is a single activity. The function should return a list of unique activities. For example, if given the argument: ['run', 'run', 'jog', 'workout', 'walk, 'run', 'walk ' then the expected return value would be run', 1 , 'jog', 'workout', 'walk'] The unique activites do not need to be returned in a specific order - any order is fine so long as all the unique words are included. (d) Now to put all of our hard work together! In the main program (outside any function), call the function clean_data() on the original list provided (physical_activity_data) to receive a new clean list. Now, call the unique_activites) function with your new clean list. Finally, use for-loops to print out each activity and the number of times it occurs in the new clean list (call the function count_activities) for each activity). Sample Output Your console output should look something like this: students run at least once a week for more than 10 minutes 14 students walk at least once a week for more than 10 minutes. 11 students jog at least once a week for more than 10 minutes 11 students bike at least once a week for more than 10 minutes. 2 students workout at least once a week for more than 10 minutes 1 students baseball at least once a week for more than 10 minutes 1 students lift at least once a week for more than 10 minutes

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!