Skip to content

Instantly share code, notes, and snippets.

@JamesIgoe
Created August 22, 2020 18:27
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 JamesIgoe/6af2553fcb17a46b00da33e14b6d733e to your computer and use it in GitHub Desktop.
Save JamesIgoe/6af2553fcb17a46b00da33e14b6d733e to your computer and use it in GitHub Desktop.
Correlation Filter: Creates a correlation matrix from a data frame. filters it for upper and lower bounds fo correlation, and then flattens it
#requires pandas and numpy
def corrFilter(x: pd.DataFrame, bound: float):
xCorr = x.corr()
xFiltered = xCorr[((xCorr >= bound) | (xCorr <= -bound)) & (xCorr !=1.000)]
xFlattened = xFiltered.unstack().sort_values().drop_duplicates()
return xFlattened
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment