Created
May 19, 2022 10:49
-
-
Save JIElite/2a7f547da04144efc431411de26516e5 to your computer and use it in GitHub Desktop.
This file contains 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
def encode_city_land_usage(x): | |
# Encode {'其他': 0, '住': 1, '農': 2, '工': 3, '商': 4, | |
# '住商': 5, '其他住宅': 6, nan: nan} | |
# nan remains | |
if not isinstance(x, str): | |
return x | |
if '非都市' in x: | |
return "" | |
if '其他' in x: | |
end_idx = x.find('(') if '(' in x else len(x) + 1 | |
if '住商' in x[:end_idx] or '住宅商業' in x[:end_idx]: | |
return 5 | |
if '住宅' in x[:end_idx] or '住' in x[:end_idx]: | |
return 6 | |
return 0 | |
if '住' in x: | |
return 1 | |
elif '農' in x: | |
return 2 | |
elif '工' in x: | |
return 3 | |
elif '商' in x: | |
return 4 | |
else: | |
# There is no such case in the data | |
raise ValueError('Unexpected 都市使用分區:', x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment