R和pands 实现dataframe的Z-score

1、导入函数

from scipy.stats import zscore

2、实现按行或列的z分数

df4=pd.DataFrame(zscore(df3,axis=1))  #实现每行的数据的z分数
df4=pd.DataFrame(zscore(df3,axis=0))  #实现每列的数据的z分数

sample:
实现每行的z分数
R和pands 实现dataframe的Z-score_第1张图片
R实现对行进行z-score

data<-read.table('./all_DEG_FPKM.txt',header = 1)
head(data)
> head(data)
            Gene         CK        N2       YCD
1    AC3.4:wp137 1.61226532 3.5582749 1.0206488
2    AC7.3:wp202 1.15972985 4.0800382 1.4821084
library(dplyr)
df10=data.frame(t(scale(t(data[,2:4])))) 
df10$Geneid=data$Gene
colnames(df10)
df11=df10 %>% select("Geneid","N2","CK","YCD")
df11<-na.omit(df11)
write.table(df11,file = 'newall_DEG_FPKM.txt',sep = '\t',row.names = F)

你可能感兴趣的:(pandas,python,r语言,python)