I made a function that reads a csv file and processed some information so I can show it in a plot in R. But with the function that I have right now my processed csv file look something like this:
1 2 3 4 12 15 16
But what I want is this in my csv file:
1
2
3
4
12
15
16
Here is what I have so far:
import csv
from datetime import datetime
from unittest import skip
end_date = datetime(day=5, month=10, year=2020, hour=23, minute=59)
fastStudent = []
allPassedStudents = []
# Open the csv file with all of the values that need to be proccesed
with open('OOP_eindopdracht\\fed_results\\WFHBOICT.OOP.20.EPIC.EXPORT.FED.20.csv', 'r') as read_obj:
# reads the whole table with as seperator ";"
csv_dict_reader = csv.reader(read_obj, delimiter=';',)
# Skips the headers
next(csv_dict_reader)
for row in csv_dict_reader:
#Looks if us11 is empty or not, if its not empty the student has passed
if row[11]:
# puts the students(row[0]) in allpassedStudents so it can be saved in a csv file
allPassedStudents.append(row[0])
# Converts the date thats in the csv(row[11]) in to datetime so it can be compared to end_date
passedDate = datetime.strptime(row[11], '%d-%m-%Y %H:%M')
if passedDate:
# look if passedDate is before the end_date and if so add it to fastStudent so it can be saved in a csv file
if passedDate < end_date:
fastStudent.append(row[0])
with open("OOP_eindopdracht\\Eindopdracht_3\\Processed_csv_file\\Behaalde_studenten.csv", 'a') as f_object:
# Pass the CSV file object to the writer() function
writer_object = csv.writer(f_object)
# Result - a writer object
# Pass the data in the list as an argument into the writerow() function
writer_object.writerow(allPassedStudents)
# Close the file object
with open("OOP_eindopdracht\\Eindopdracht_3\\Processed_csv_file\\Snelle_studenten.csv", 'a') as f_object:
# Pass the CSV file object to the writer() function
writer_object = csv.writer(f_object)
# Result - a writer object
# Pass the data in the list as an argument into the writerow() function
writer_object.writerow(fastStudent)
# Close the file object