I would like to create a new column to classify if certain address is a residential or non-residential address.
Below is a column in the original dataframe:
| Building_name |
|---|
| Fung Chak House, Choi Wan (II) Estate |
| Princess Margaret Hospital (non-residential) |
And I write the below code to create a new column if the string "non-residential" is in Building_name it would be classified as Non-residential, otherwise it would be Residential.
def build_cat(row):
if "(non-residential)" not in district_df['Building_name']:
return ("Residential")
if '(non-residential)' in district_df['Building_name']:
return ('Non_residential')
district_df['Building_category'] = district_df.apply(lambda row: build_cat(row), axis =1)
However, the about function returns everything as Residential.
| Building_name | Building_cateory |
|---|---|
| Fung Chak House, Choi Wan (II) Estate | Residential |
| Princess Margaret Hospital (non-residential) | Residential |
Appreciate if you can let me know what's wrong in my code, or if there are other more efficient ways to get the same result.
Thanks.