I am currently trying to develop a program that reads data from a text file, and returns the pair of employees that has worked the most time together. I decided to it in a .CSV format, as that is still a plain text format, but seperated with comas.
Example:
EmpID,ProjectID,DateFrom,DateTo
1,A,2014-11-01,2015-05-01
2,B,2013-12-06,2014-10-06
2,C,2014-01-07,2016-03-07
3,B,2015-06-04,2017-09-04
5,C,2014-10-01,2015-12-01
1,A,2013-03-07,2015-11-07
2,C,2015-07-09,2019-01-19
3,B,2013-11-13,2014-03-13
4,C,2016-02-14,NULL
5,D,2014-03-15,2015-11-09
Now, I learned how to read .CSV files, but I am not sure on what is the best way for the thing after (the comparing of values, etc). For now, I decided that this is the cleanest option:
import csv
with open('data.csv', 'r') as f:
reader = csv.reader(f)
your_list = list(reader)
print(your_list)
I just want a piece of advice, if the best way to go would be with comparing indexes of the list. I was also thinking about dictionaries, but I am not sure, hence the reason I am asking here :) And SQL is not an option, even though it would be so easy with it. Sorry if this is a bad question, but I am currently learning Python and this is quite an important task for me. Thanks!
Employeeclass and use each line to create an Employee object. This reduces complexity because it's much easier to refer to, say, an employee's id asemployee.idinstead of an index of a list or a key in a dictionary, andEmployee's methods could deal with the logic afterwards. This of course requires you to learn at least some object oriented programming basics in Python, however.pandasvote, the library is set up specifically to handle this kind of problem. I've linked theread_csvmethod