Skip to content

Instantly share code, notes, and snippets.

@patrickbrus
Created November 10, 2021 06:09
Show Gist options
  • Save patrickbrus/c7e1c29f189010710d2d6ba98344f38f to your computer and use it in GitHub Desktop.
Save patrickbrus/c7e1c29f189010710d2d6ba98344f38f to your computer and use it in GitHub Desktop.
# Compute GDP by using GDP per capita and the Population columns
df_final["GDP"] = df_final["GDP per capita"] * df_final["Population"]
# Remove % sign of Population under 20 years old column and convert it to be of type float
def transform_col(col_val):
try:
return float(col_val.replace(" %", ""))
except: # value is NaN
return col_val
df_final["Population under 20 years old in %"] = df_final["Population under20 years old"].apply(transform_col)
df_final = df_final.drop(columns=["Population under20 years old"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment