Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. # The clinic names and addresses are mixed
  2. clinic_col = ("PERIOD,PRACTICE,CLINIC NAME ONE,CLINIC NAME TWO,ROAD NAME,"
  3. "TOWN,COUNTY,UNKNOWN").split(",")
  4. clinic = pd.read_csv("uk_drug_prescription/T201611ADDR+BNFT.CSV",
  5. names = clinic_col)
  6.  
  7. # Remove whitespace from all the columns
  8. rm_ws_col = ("CLINIC NAME ONE,CLINIC NAME TWO,ROAD NAME,TOWN,COUNTY,"
  9. "UNKNOWN").split(",")
  10. for i in rm_ws_col:
  11. clinic[i] = list(map(rm_ws, clinic[i]))
  12.  
  13. # Arrange the clinic names and road names into correct columns
  14. a = clinic.loc[:, "CLINIC NAME TWO"]
  15. b = clinic.loc[:, "ROAD NAME"]
  16. tf = clinic.loc[:, "ROAD NAME"] == ""
  17. for key, value in enumerate(tf):
  18. if value == True:
  19. a.iloc[key], b.iloc[key] = b.iloc[key], a.iloc[key] # swapping values
  20. # shallow.copy
  21.  
  22. # Remove all dashes in TOWN and COUNTY column
  23. def remove_dashes(row, column):
  24. t = row[column]
  25. return re.sub(r"-", " ", t)
  26.  
  27. town_dashes = partial(remove_dashes, column = "TOWN")
  28. clinic["TOWN"] = clinic.apply(town_dashes, axis = 1)
  29. county_dashes = partial(remove_dashes, column = "COUNTY")
  30. clinic["COUNTY"] = clinic.apply(county_dashes, axis = 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement