
- 10th Jul 2024
- 18:11 pm
You will develop a script in a file named process_grades.py that will read some grade data, process it, and output the processed results. Set Up Your Programming Environment Develop this script with any python IDE you wish. Read in Grade Data The first thing your script should do is open a file called grades.csv and read in all of the values. This file will contain an arbitrary number of lines in CSV format (comma-separated values). The data will be formatted this way: the first two values will be the last name and first name of the student, in that order. These will be strings (the strings will not be quoted). the next 8 values will be preparation assignment scores. These will be integers between 0 and 10. There may or may not be spaces before or after the numbers (for these and all following values) the next 8 values will be lab scores. These will be integers between 0 and 30. the next 2 values will be the project #1 and project #2 scores, respectively. These will be integers between 0 and 100. the next 4 values will be exam scores. These will be integers between 0 and 160. Each line will represent the scores for a single student in CSC184 this semester. Below are some fake data fitting this format. Note that I will test your programs with a variety of files similar to this! grades.csv Validate Data In the previous section, there is a specification for exactly how many values each line should hold and what type and range each value should fit into. If there is any deviation from this specification in the data being read in by your script, it should not crash with a runtime error. Instead, it should halt processing the file and output a helpful error message that is useful to the user, identifying the line number that the error occurred on and, as best as you can, what the problem with the data was. Similarly, if the file grades.csv does not exist in the working directory, an appropriate error message should be given to the user. Under no circumstances should the user see a python stack trace.
Data Wrangling Project Solution And Tutoring Help
Please note that this is a sample Data Wrangling project solved by our Python Experts. These solutions are intended to be used for research and reference purposes only. If you can learn any concepts by going through the reports and code, then our Python Tutors would be very happy.
- To download the complete solution along with Code, Report and screenshots - Please visit our Python Assignment Sample Solution page
- Reach out to our Python Tutors to get online tutoring related to this assignment and get your doubts cleared
- You can check the partial solution for this assignment in this blog below
Free Project Solution - Data Wrangling
import csv
data_list = []
final_record = []
# this function reads the csv and store it in list
def read_csv():
try:
with open('grades.csv') as file:
csv_reader = csv.reader(file)
for row in csv_reader:
data_list.append(row)
return True
except:
print('Cannot read the file grades.csv')
return False
# this function write to csv
def write_csv():
try:
with open('final_grades.txt' , 'w', newline='') as file:
csv_writer = csv.writer(file)
csv_writer.writerows(final_record)
print('Data in file final_grades.txt')
except:
print('Cannot write data file final_grade.txt')
# this function returns the percent of marks at a given index
def get_score(start_index, last_index, full_marks, list):
total = 0
count = 0
for i in range(start_index, last_index):
total = total + int(list[i])
count = count + 1
percent = (total / (count * full_marks) ) * 100
percent = round(percent, 1)
return percent
# this function get the percent score dropping the lowest
def get_percent_dropping(start_index, last_index, full_marks, list, droping_count):
new_list = []
for i in range(start_index, last_index):
new_list.append(int(list[i]))
new_list = sorted(new_list) # sorting the list
total = 0
count = 0
for i in range(droping_count, len(new_list)):
total = total + int(new_list[i])
count = count + 1
percent = (total / (count * full_marks) ) * 100
percent = round(percent, 1)
return percent
# this function returns the grade according to the score
def get_grade(score):
if score >= 90:
return 'A'
elif score >= 80:
return 'B'
elif score >= 70:
return 'C'
elif score >= 60:
return 'D'
else:
return 'F'
#this function ins the main which run the code
def main():
if read_csv() == True:
line_number = 1
for row in data_list:
if len(row) == 24:
l = []
last_name = row[0]
first_name = row[1]
prep_assignemt_score = get_score(2,10,10,row)
lab_score = get_percent_dropping(10,18,30,row,2)
project_score = get_score(18,20,100,row)
exam_score = get_percent_dropping(20,24,160,row,1)
final_score = 0.08 * prep_assignemt_score + 0.24 * lab_score + 0.2 * project_score + 0.48 * exam_score
final_score = round(final_score, 1)
l.append(last_name)
l.append(first_name)
l.append(prep_assignemt_score)
l.append(lab_score)
l.append(project_score)
l.append(exam_score)
l.append(final_score)
l.append(get_grade(final_score))
final_record.append(l) # appending data into the list
else:
print(line_number,"doesnot contains the appropriate value of grades")
line_number = line_number + 1
write_csv()
if __name__ == '__main__':
main()
Get the best Data Wrangling Project help and tutoring services from our experts now!
About The Author - Emily Davis
Emily Davis is a skilled software developer specializing in Python programming and data processing. She excels in creating efficient, user-friendly scripts for educational applications. In this project, Emily demonstrates her expertise by developing process_grades.py
, a Python script designed to read, validate, process, and output student grade data accurately. Her focus on clear error handling and clean code ensures a smooth user experience.