Skip to content

Instantly share code, notes, and snippets.

@KalebNyquist
Created September 13, 2019 16:22
Show Gist options
  • Save KalebNyquist/4403df5d1785436635d5e75ef7d58df5 to your computer and use it in GitHub Desktop.
Save KalebNyquist/4403df5d1785436635d5e75ef7d58df5 to your computer and use it in GitHub Desktop.
Strange Zeroes #EDA
import pandas as pd
import numpy as np
def strange_zeroes(dataset, drop_columns = None, zero = 0):
"""Exploratory Data Analysis function that looks to see if there is any correlation between '0' values occurerence,
which would suggest a relationship between the instruments used and their non-detection of a value."""
# Find all zeroes (can be altered to including other common missing / non-response values as well)
zeroes = (dataset == zero)
# Cleaning Code (Optional)
if drop_columns != None:
zeroes = zeroes.drop(drop_columns, axis=1)
# SOURCE: https://stackoverflow.com/a/50703596
corr = zeroes.corr()
return corr.style.background_gradient(cmap='coolwarm') # NOTE: 'RdBu_r' & 'BrBG' are other good diverging colormaps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment