Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. # To change the county names to the correct county names as much as possible
  2. def check_county(row):
  3. cl = row[["TOWN", "COUNTY"]]
  4. all_town = list(list_towns["TOWN"].unique())
  5. all_county = list(list_towns["COUNTY"].unique())
  6. ct = ""
  7.  
  8. # Match the county to the town from the list_towns dataset
  9. if cl["TOWN"] in all_town:
  10. obs = list_towns[list_towns["TOWN"] == cl["TOWN"]]
  11. ct = obs["COUNTY"].iloc[0]
  12.  
  13. # If town data absent, use county data if county data present
  14. elif ct == "":
  15. for i in all_county:
  16. if i in cl["COUNTY"]:
  17. ct = i
  18. break
  19. else:
  20. ct = cl["COUNTY"]
  21. return ct
  22.  
  23. clinic["tCOUNTY"] = clinic.apply(check_county, axis = 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement