I am very new to Python but I'm trying to learn more and my first mini project that I've given myself is to create a code that can receive the input for a given user name and then output the amount of hours they worked on a certain project. I receive a csv at the end of the week for employees in my department and within that csv I have various projects that they are working on and the hours dedicated to that project. The catch with the csv file is there are duplicate projects for that user so when my csv outputs I need it to only show one project name and ALL the hours associated with that project. How can I get my code to read the duplicates and only count the hours from the duplicates and just use one project name?
Here is the code I've come up with so far:
import csv
with open('Report.csv') as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
firsts = []
lasts = []
projects = []
hours = []
for row in readCSV:
first = row[0]
last = row[1]
project = row[2]
hour = row[3]
firsts.append(first)
lasts.append(last)
projects.append(project)
hours.append(hour)
First_name = input("Please enter the first name: ")
First_1 = firsts.index(First_name)
Last_1 = lasts[First_1]
project_1 = projects[First_1]
hours_1 = hours[First_1]
print(First_1, Last_1, project_1, hours_1)
Here is a sample of the csv
First Last Project Hours
David Ayers AD-0002 Training 24
Oriana Morfitt AD-0002 Training 24
David Ayers AD-0003 Personal Time 8
David Ayers AD-0004 Sick Time 0
Oriana Morfitt AD-0005 Vacation 40
Sujatha Kavuri Beeline Blank 29
Sujatha Kavuri Beeline Blank 16
Sujatha Kavuri OPS-0001 General Operational Support 6
Jeff Moore OPS-0001 General Operational Support 5
Sri Mantri SRV-0001 Service Requests for Base and Direct Services 4
Prasanth Musunuru SRV-0001 Service Requests for Base and Direct Services 11
Prasanth Musunuru SRV-0001 Service Requests for Base and Direct Services 10
Jeff Moore SRV-0006 Standards and Processes 5
Jeff Moore SRV-0006 Standards and Processes 3
Jeff Moore SRV-2503 Internet Access Infrastructure Maintenance & Support 12.5
Jeff Moore SRV-2503 Internet Access Infrastructure Maintenance & Support 7
Jeff Moore 0024495915 Work Instructions (infrastructure) - time tracking 1
Sri Mantri 0026184229 Margin Controlling Java Rewrite 4
Sujatha Kavuri 0029157489 SCRM Life Cycle Extension 3
Jeff Moore 0031369443 Shopcall Attachment Changes 1
Jeff Moore 0031500942 MP Strategy 2015 - Spot PO via EDI (time tracking only) - 0031500942 1