Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. mport rows
  2. from collections import OrderedDict
  3. from rows import fields, Table
  4. import tqdm
  5.  
  6. files = [
  7. ("2017Q2-Q1","Descargas/2017Q2_Positive_Employer_EN.csv"),
  8. ("2017Q3","Descargas/2017Q3_Positive_Employer-EN.csv"),
  9. ("2017Q4","Descargas/2017Q4_Positive_Employer-EN.csv"),
  10. ("2018Q1","Descargas/2018Q1_Positive_Employer_EN.csv"),
  11. ("2018Q2","Descargas/2018Q2_Positive_Employer_EN.csv"),
  12. ("2018Q3","Descargas/2018Q3_Positive_Employer_en.csv"),
  13. ("2018Q4","Descargas/2018Q4_Positive_Employer_en.csv"),
  14. ]
  15.  
  16. outputs =[]
  17.  
  18. for ph, fi in tqdm.tqdm(files):
  19. output = rows.import_from_csv(fi)
  20. outputs.append((ph,output))
  21.  
  22. set_fields = OrderedDict([
  23. ('year', fields.TextField),
  24. ("location", fields.TextField),
  25. ("company", fields.TextField),
  26. ("address", fields.TextField),
  27. ("noc", fields.TextField),
  28. ("count", fields.TextField),
  29. ])
  30.  
  31. out = Table(fields = set_fields)
  32.  
  33.  
  34.  
  35. for year,output in tqdm.tqdm(outputs):
  36. location, company, address = None, None, None
  37. for row in tqdm.tqdm(output):
  38. location_field = row[0].strip()
  39. company_field = row.field_1.strip()
  40. address_field = row.field_2.strip()
  41. noc_field = row.field_3.strip()
  42. count_field = row.field_4.strip()
  43. if location_field:
  44. location = location_field
  45. address = address_field
  46. if company_field:
  47. company = company_field
  48. if noc_field.strip():
  49. out.append({
  50. 'year':year,
  51. 'location':location, 'company': company,
  52. 'address':address, 'noc': noc_field,
  53. 'count':count_field
  54. })
  55. #print(location, company, address_field, noc_field, count_field)
  56.  
  57.  
  58. rows.export_to_csv(out, "out.csv")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement