Jan-29-2020, 05:45 PM
I use the below code to produce the correlation and the p-value.
My questions are :
1. If there are many independent variables (Y) -- there are only 3 ind variables in the below example, how can I include all of them in the below code without hard code them?
2. How can I export the output to excel or csv file?
2 OBJ Acct_Tenure 1000 0.082 0.009059
0 OBJ Acct_Tenure_1st_of_Month 1000 0.082 0.009206
1 OBJ H_XtraCare_Flag 1000 0.057 0.073851
Thanks.
My questions are :
1. If there are many independent variables (Y) -- there are only 3 ind variables in the below example, how can I include all of them in the below code without hard code them?
2. How can I export the output to excel or csv file?
# Calculate the Pearson correlation import pingouin as pg corr = pg.pairwise_corr(random_subset, columns=[['OBJ'], ['Acct_Tenure_1st_of_Month', 'H_XtraCare_Flag', 'Acct_Tenure']], method='pearson') corr.sort_values(by=['p-unc'])[['X', 'Y', 'n', 'r', 'p-unc']].head()X Y n r p-unc
2 OBJ Acct_Tenure 1000 0.082 0.009059
0 OBJ Acct_Tenure_1st_of_Month 1000 0.082 0.009206
1 OBJ H_XtraCare_Flag 1000 0.057 0.073851
Thanks.