Using Python, write a code that reads a Microsoft Excel CSV file named \"LabAssi
ID: 3870753 • Letter: U
Question
Using Python, write a code that reads a Microsoft Excel CSV file named "LabAssignment"
The CSV file contains 25 colums as well close to 200 rows of data.
Write a code in Python so that:
It removes all unwanted columns along with its data...the columns that should be kept have the following header: "User" "Location" "Feature" "HoursUsed"
Remove all files with the "User" Billy
it outputs the data in the following order by column header:
"User" "Location" "Feature" "HoursUsed"
for "HoursUsed" make sure all the hours are added up
for "Location" remove "HOST:"
EXAMPLE
CSV file contains:
"Location" "Feature" "User" "NumUser" "HoursUsed" (and 20 more column headers...)
HOST: USA test Bob 1 0.5
HOST::USA test Billy 1 1
HOST: USA test Bob 1 1
HOST: USA test2 Bob 1 2.5
HOST: USA test2 Jill 1 1
Output:
"User" "Location" "Feature" "HoursUsed"
Bob USA test 1.5
Bob USA test2 2.5
Jill USA test2 1
Explanation / Answer
import csv
reader = csv.reader(open("LabAssignment.csv"), delimiter=',')
data = sorted(reader, key=operator.itemgetter('feature'))
groups = itertools.groupby(data, operator.itemgetter('feature'))
for line in reader:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.