How to apply scipy function on Pandas data frame

Viewed 2231

I have the following data frame:

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

It looks like this

                     sample1  sample2  sample3
probegenes
1415777_at Pnliprp1       20        0       11
1415805_at Clps           17        0       55
1415884_at Cela3b         47        0      100

What I want to do is too perform row-zscore calculation using SCIPY. Using this code I get:

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 ]])

How can I conveniently attached the columns and index name back again to that result?

At the end of the day. It'll look like:

                               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
2 Answers
Related