concept Python in category churn

This is an excerpt from Manning's book Fighting Churn with Data.
The book is written from the point of view of a “data person”, meaning whoever is expected to take the raw data and come up with useful findings to help in the fight against churn. That person might have the title data scientist, data analyst, or machine learning engineer. Or they may be someone else who knows a bit about data and code and is being asked to fill those shoes. The book uses Python and SQL so it does assume that the data person is a coder. Although I advocate spreadsheets for presentation and sharing data (as I detail in the book) I do not recommend attempting the main analytic tasks of churn fighting in spreadsheets: There are many tasks that must be performed in sequence, and some of these are non trivial. And there is a need to “rinse and repeat” the process multiple times - that kind of workflow is well suited to short programs but difficult in spreadsheets and graphical tools.
In section 6.1 this chapter starts with some case studies to demonstrate what it means for behaviors to be correlated and then teaches you how to calculate correlations in your own data with Python and with something called a correlation matrix, which is an important way of looking at correlations between a large number of metrics.
Listing 6.2 Calculating the correlation matrix for a dataset in Python
import pandas as pd import os def dataset_correlation_matrix(data_set_path): assert os.path.isfile(data_set_path), '"{}" is not a valid path'.format(data_set_path) #A churn_data = pd.read_csv(data_set_path,index_col=[0,1]) #B churn_data = churn_data.reindex(sorted(churn_data.columns), axis=1) #C corr_df = churn_data.corr() #D save_name = data_set_path.replace('.csv', '_correlation_matrix.csv') corr_df.to_csv(save_name) #E print('Saved correlation matrix to' + save_name)