Skip to content

Instantly share code, notes, and snippets.

@WillKoehrsen
Created May 7, 2018 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WillKoehrsen/907b143686108592ec94e83fde3584af to your computer and use it in GitHub Desktop.
Save WillKoehrsen/907b143686108592ec94e83fde3584af to your computer and use it in GitHub Desktop.
# Replace the string for missing values with not a number
data = data.replace({'Not Available': np.nan})
# Iterate through the columns
for col in list(data.columns):
# Select columns that should be numeric using string matching
if ('ft²' in col or 'kBtu' in col or 'Metric Tons CO2e' in col or 'kWh' in
col or 'therms' in col or 'gal' in col or 'Score' in col):
# Convert the data type to float
data[col] = data[col].astype(float)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment