On 10/04/2017 04:48 PM, Dennis Lee Bieber wrote:
On Wed, 4 Oct 2017 09:42:18 -0700, 20/20 Lab <l...@2020fresno.com> declaimed
the following:

        Well -- since your later post implies this is not some "homework
assignment"...

Looking for advice for what looks to me like clumsy code.

EMP1 = [0,0]
EMP2 = [0,0]
EMP3 = [0,0]

        EEEK! Don't do that! Especially as...

for line in (inputfile):
     content = line.split(",")
        You've already been told to use the CSV module, since it should handle
tricky cases (quoted strings with embedded commas, say).

     if content[18] == "EMP1":
... the name is part of the input data. Use a data structure in which the
name is part of the data -- like a dictionary.

         if float(content[24]) < 99.75:
             EMP1[0] += 1
         elif float(content[24]) > 99.74:
             EMP1[1] += 1
        Pardon? Floating point numbers are not exact... It is possible that
some entry, in floating binary, is really between 99.75 and 99.74, so which
should it be counted as? At the least, just use an else: for the other
case.



employees = {}
for row in csvfile: #pseudo-code for however you read each row of data

        emp = employees.get(content[18], [0, 0])
        if float(content[24]) < 99.75
                emp[0] += 1
        else:
                emp[1] += 1
        employees[content[18]] = emp


and repeat if statements for the rest of 25+ employees.  I can make a
list of the employees, but I'd prefer to pull them from the csv, as our
turnover is rather high (however this is not important).  I'm thinking
another "for employee in content[18]" should be there, but when I tried,
my numbers were incorrect.
        Actually -- I'd be more likely to load the data into an SQLite3
database, and use SQL queries to produce the above summary report. I'd have
to experiment with subselects to get the > and < sets, and then use a
count() and groupby to put them in order.
Thanks!  I knew there was an more refined way to do this.  I'm still learning, so this is a huge help. The data actually already comes from a database, but doesnt allow me to produce a summary report, just a list of of each item.  Which I can then export to pdf, or the csv that I'm working with.  The developers have a ticket for a feature request, but they've had it there for over five years and I dont see them implementing it anytime soon.
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to