Skip to content

Instantly share code, notes, and snippets.

@abbasali-io
Created February 2, 2020 16:34
Show Gist options
  • Save abbasali-io/ec48da520c277d369138b524c101828f to your computer and use it in GitHub Desktop.
Save abbasali-io/ec48da520c277d369138b524c101828f to your computer and use it in GitHub Desktop.
Split the Built Up Type & Built Up Area Size into two separate columns, i.e. Built_Type & Built_Size, and show the top 5 rows of the dataframe to view the effect
# define the function to split Size into an array of two differnt values
def split_property_size(size, tp=0):
try:
return size.split(":")[tp].strip()
except AttributeError:
return size
#create a new column with the buildup type
df["Built_Type"] = df['Size'].astype(str).apply(split_property_size, tp=0)
df["Built_Type"].value_counts(dropna=False)
df["Built_Size"] = df['Size'].apply(split_property_size, tp=1)
df["Built_Size"].value_counts(dropna=False)
df.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment