Sorted Absolute Correlation Table

Python

Display the correlation and absolute column values between the numerical columns in the DataFrame and the 'target' column.

 1|  def correlation_table(data,target_column):
 2|  	data_num = data.select_dtypes(include=['int','float'])
 3|  	corr_df = pd.DataFrame(data_num.corrwith(data_num[target_column]),columns=['Correlation']).dropna()
 4|  	corr_df['ABS Correlation'] = abs(corr_df['Correlation'])
 5|  	corr_df.sort_values(by=['ABS Correlation'], ascending=False, inplace=True)
 6|  	print(corr_df)
 7|  
 8|  correlation_table(df, 'target')
Sorted Absolute Correlation Table
Did you find this snippet useful?

Sign up for free to to add this to your code library