申请SciPy的功能,我有以下的数据帧:如何在大熊猫数据帧
import pandas as pd
import io
from scipy import stats
temp=u"""probegenes,sample1,sample2,sample3
1415777_at Pnliprp1,20,0.00,11
1415805_at Clps,17,0.00,55
1415884_at Cela3b,47,0.00,100"""
df = pd.read_csv(io.StringIO(temp),index_col='probegenes')
df
它看起来像这样
sample1 sample2 sample3
probegenes
1415777_at Pnliprp1 20 0 11
1415805_at Clps 17 0 55
1415884_at Cela3b 47 0 100
我想要做的是执行过什么row-zscore calculation using SCIPY。 使用此代码我得到:
In [98]: stats.zscore(df,axis=1)
Out[98]:
array([[ 1.18195176, -1.26346568, 0.08151391],
[-0.30444376, -1.04380717, 1.34825093],
[-0.04896043, -1.19953047, 1.2484909 ]])
我怎样才能方便地连接列和索引名回 再次到该结果呢?
在一天结束时。它会像:
sample1 sample2 sample3
probegenes
1415777_at Pnliprp1 1.18195176, -1.26346568, 0.08151391
1415805_at Clps -0.30444376, -1.04380717, 1.34825093
1415884_at Cela3b -0.04896043, -1.19953047, 1.2484909
不能这样做'S = pd.DataFrame(stats.zscore(DF,轴= 1),指数= df.index,列= df.columns) '? – EdChum