Created
September 25, 2013 17:04
-
-
Save pmarkun/6702718 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import csv, codecs | |
| import simplejson as json | |
| import operator | |
| arquivo = codecs.open('raw/20130731_Remuneracao.csv', 'rU') | |
| reader = csv.DictReader((line.replace('\0','') for line in arquivo), delimiter='\t') | |
| first_names = { 'TOTAL' : 0} | |
| lista = [] | |
| second_loop = [] | |
| print 'First loop...' | |
| for i in reader: | |
| if 1==1: | |
| nome = i['NOME'].split() | |
| if not first_names.has_key(nome[0]): | |
| first_names[nome[0]] = 1 | |
| else: | |
| first_names[nome[0]] += 1 | |
| first_names['TOTAL'] += 1 | |
| second_loop.append({'nome' : i['NOME'].split(), 'salario' : i['REMUNERA\xc7\xc3O B\xc1SICA BRUTA (R$)']}) | |
| names = { 'TOTAL' : { 'count' : 0, 'salario' : 0.0}} | |
| print 'Second loop...' | |
| for i in second_loop: | |
| i['salario'] = float(i['salario'].replace(',','.')) | |
| if first_names.has_key(i['nome'][1]) and first_names[i['nome'][1]] > 100: | |
| if not names.has_key(i['nome'][0] + ' ' + i['nome'][1]): | |
| names[i['nome'][0] + ' ' + i['nome'][1]] = { 'salario' : i['salario'], 'count' : 1 } | |
| else: | |
| names[i['nome'][0] + ' ' + i['nome'][1]]['count'] += 1 | |
| names[i['nome'][0] + ' ' + i['nome'][1]]['salario'] += i['salario'] | |
| elif not names.has_key(i['nome'][0]): | |
| names[i['nome'][0]] = { 'salario' : i['salario'], 'count' : 1 } | |
| else: | |
| names[i['nome'][0]]['count'] += 1 | |
| names[i['nome'][0]]['salario'] += i['salario'] | |
| names['TOTAL']['count'] += 1 | |
| names['TOTAL']['salario'] += i['salario'] | |
| print 'Sorting and printing for TODOS...' | |
| fifteen_names = sorted(names.iteritems(), key=lambda x:x[1]) | |
| fifteen_names.reverse() | |
| for i, f in enumerate(fifteen_names[1:51]): | |
| media = "{0:.2f}".format(f[1]['salario']/f[1]['count']) | |
| print f[0] + ',' + media | |
| for p in names: | |
| names[p]['media'] = names[p]['salario']/names[p]['count'] | |
| riches = sorted(names.iteritems(), key=lambda x:x[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment