COMP 1012 Programming Fundamentals and Applications Assignment 3
- Task 1 – (20 Points)
Given counting.csv in the Data folder, please write a Python program to estimate the counts 2 minutes and 30 seconds after each timestamp. Then, store the counts for every 2 minutes and 30 seconds in a csv file named results_T1.csv in the Results folder. Plot the counts for every 2 minutes and 30 seconds and save as a png file named result_plot_T1.png in the results folder. For example, supposed we have
Time | Counts |
---|---|
9/2/2022 7:35:00 AM | 6 |
9/2/2022 7:40:00 AM | 8 |
9/2/2022 7:45:00 AM | 10 |
We are going to estimate the counts at 9/2/2022 7:37:30 AM, 9/2/2022 7:42:30 AM, and 9/2/2022 7:47:30 AM, respectively, and store it as a csv file. Time | Counts |
---|---|
9/2/2022 7:35:00 AM | 6 |
9/2/2022 7:37:30 AM | Estimated counts |
9/2/2022 7:40:00 AM | 8 |
9/2/2022 7:42:30 AM | Estimated counts |
9/2/2022 7:45:00 AM | 10 |
9/2/2022 7:47:30 AM | Estimated counts |
Requirements: Please use pandas to read and write the csv file. Tips: You can use interpolation methods provided by NumPy or SciPy to estimate the counts. You can also try using linear regression in scikit-learn for the estimation (see the reference: https://scikitlearn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html and https://scikitlearn.org/stable/auto_examples/linear_model/plot_ols.html).
- Task 2 – (40 Points)
Please write a Python program to
- Ask user to input a string from keyboard. The string must contain at least a ‘\’, a space, a lowercase letter, an upper-case letter, and a number. If the input string does not satisfy the rule, ask the user to re-input.
- Print the obtained string.
- Replace all the ‘\’ by ‘n’ in the obtained string.
- Replace all the lower-case letters by ‘\’ in the obtained string.
- Replace all the upper-case letters by ‘t’ in the obtained string.
- Replace all the numbers by ‘*’ in the obtained string.
- Print the new string.
Tips: Since all string manipulation is replacing, the length of the string after replacing must be the same as the original one. Be careful about escape characters. You can check string methods in https://www.w3schools.com/python/python_ref_string.asp.
- Task 3 – (40 Points)
Please write a Python program to
- Ask the user to input ?? float number and store in a list named nums, where ?? ≥ 3.
- Return the output list named res where the length of res is the same as the nums, and res[i] is equal to the product of the elements of nums excluding nums[i] where 0 < ?? < ??????(??????).
- Print every nums[i] and format the output to keep 4 decimal places.
Requirement:
- Division is not allowed.
- Nested loop is not allowed.
Tips: Since all string manipulation is replacing, the length of the string after replacing must be the same as the original one. Be careful about escape characters. You can check string methods in https://www.w3schools.com/python/python_ref_string.asp.
- Submission Requirement
- Submit on time.
- Name the program of Task 1 by studentID_T1.py in which studentID is your student ID. For example, if your student ID is 12345678g, name the program as 12345678g_T1.py.
- Name the program of Task 2 by studentID_T2.py in which studentID is your student ID. For example, if your student ID is 12345678g, name the program as 12345678g_T2.py.
- Name the program of Task 3 by studentID_T3.py in which studentID is your student ID. For example, if your student ID is 12345678g, name the program as 12345678g_T3.py.
- Put studentID_T1.py, studentID_T2.py and studentID_T3.py into a folder named by your student ID.
- Create a folder named Data in the folder student ID and put counting.csv in the Data folder.
- Create a folder named Results in the folder student ID.
- studentID_T1.py should read the counting.csv in the Data folder as input of the program and the outputs should be automatically saved in the Results folder.
- Zip the folder and submit the zip file via the Blackboard.
- End –