分析思路:
1.導(dǎo)入必要的包(pandas,numpy,scipy.stats,matplotlib.pyplot,seaborn)
2.讀取文件,為df
3.按 department 分組并獲得索引 dp_indices ;
4.?得到分組后 dp_indices 的keys鍵;
5.初始化一個矩陣 dp_t_mat ,矩陣的寬和高都是len(dp_keys);
6.行(i)列(j)各自遍歷每個數(shù)據(jù)后,通過 left 行號索引對應(yīng)行keys的數(shù)據(jù),用 scipy.stats.ttest 求交叉后 t 檢驗的 p 值;
7.如果 t 檢驗的P值小于0.05賦-1,否則等于P(這步是讓heatmap繪出的圖形,更加具有區(qū)分性);
8.把P值賦給矩陣;
9.繪制圖形
(注意:t 檢驗的p值越小,二者差異越大,越不相關(guān))

交叉分析實現(xiàn)代碼

heatmap繪制出的圖形