Académique Documents
Professionnel Documents
Culture Documents
df = pd.read_excel('AMPATUAN-FLORDELIZA-MHA.xlsx',
sheet_name='Correlation')
print(df)
1 P2 32 4 38 45 47
2 P3 33 2 24 37 40
3 P4 32 4 30 31 35
4 P5 49 2 20 33 33
5 P6 40 4 30 38 33
6 P7 35 4 28 40 36
7 P8 37 4 25 42 41
8 P9 33 4 26 41 34
9 P10 32 4 28 42 39
10 P11 39 4 31 38 34
11 P12 40 4 33 42 34
12 P13 35 4 26 41 37
13 P14 32 4 30 45 34
14 P15 33 4 24 41 36
15 P16 31 4 23 42 36
16 P17 32 3 22 34 39
17 P18 28 4 24 45 35
18 P19 30 3 22 34 39
19 P20 27 3 20 42 41
20 P21 28 3 29 40 36
21 P22 29 3 33 47 35
22 P23 30 3 26 42 38
23 P24 31 3 24 47 42
24 P25 40 3 22 34 39
25 P26 31 3 22 34 39
26 P27 28 3 20 42 41
27 P28 30 3 20 41 43
28 P29 29 3 21 42 41
29 P30 30 3 26 30 44
30 P31 25 3 26 30 44
31 P32 29 3 28 40 30
32 P33 28 3 25 41 36
33 P34 30 3 32 41 35
34 P35 28 3 28 41 35
35 P36 28 3 26 42 37
36 P37 29 3 37 47 36
37 P38 30 3 26 45 38
38 P39 27 3 24 35 44
39 P40 28 3 26 30 45
40 P41 37 4 26 43 41
41 P42 30 4 26 43 34
42 P43 32 4 26 46 41
43 P44 35 4 25 45 34
corr_matrix = df.corr(method='pearson')
corr_matrix.round(decimals=1)
print(corr_matrix)
sn.heatmap(corr_matrix, annot=True)
plt.show()
sn.pairplot(corr_matrix, kind='reg', diag_kind='kde')
<seaborn.axisgrid.PairGrid at 0x1bce2bf51c0>
def calculate_pvalues(df):
dfcols = pd.DataFrame(columns=df.columns)
pvalues = dfcols.transpose().join(dfcols, how='outer')
for r in df.columns:
for c in df.columns:
tmp = df[df[r].notnull() & df[c].notnull()]
pvalues[r][c] = round(pearsonr(tmp[r], tmp[c])[1], 4)
return pvalues
pvals = calculate_pvalues(corr_matrix)
# Label the matrix with "Significant" where the mask is True, and "Not
Significant" where the mask is False
matrix_labels = np.where(mask, "Significant", "Not Significant")
# Print the original matrix and its labels
print("Original matrix:")
print(pvals)
print("\nMatrix with labels:")
print(matrix_labels)
Original matrix:
Age Tenure Autonomy Environmental
Mastery \
Age 0.0 0.1219 0.163 0.589
Total satisfaction
Age 0.0
Tenure 0.2826
Autonomy 0.2805
Environmental Mastery 0.1021
Personal Growth 0.8465
Positive Relations 0.3067
Purpose in Life 0.0335
Self-Acceptance 0.0771
Pay 0.0001
Promotion 0.0587
Supervision 0.3868
Fringe Benefits 0.0
Contingent rewards 0.0014
Operating conditions 0.4297
Coworkers 0.0
Nature of work 0.0157
Communication 0.0235
Total satisfaction 0.0
df_pvalues = pd.DataFrame(matrix_labels)
print(df_pvalues)
0 1 2 3
\
0 Significant Not Significant Not Significant Not Significant
1 Not Significant Significant Significant Significant
4 5 6 7
\
0 Not Significant Not Significant Significant Not Significant
8 9 10 11
\
0 Significant Not Significant Not Significant Significant
12 13 14 15
\
0 Significant Not Significant Significant Significant
16 17
0 Significant Significant
1 Significant Not Significant
2 Significant Not Significant
3 Significant Not Significant
4 Not Significant Not Significant
5 Not Significant Not Significant
6 Not Significant Significant
7 Significant Not Significant
8 Not Significant Significant
9 Not Significant Not Significant
10 Not Significant Not Significant
11 Significant Significant
12 Not Significant Significant
13 Not Significant Not Significant
14 Not Significant Significant
15 Not Significant Significant
16 Significant Significant
17 Significant Significant
corr_matrix.to_excel("output.xlsx",sheet_name="Corr_matrix")
pvals.to_excel("pvalues.xlsx",sheet_name="pvalues")
df_pvalues.to_excel("Significance.xlsx",sheet_name = "significance")