5
我有两个DataFrames
:如何订购并保留常用指标从两个DataFrames
import pandas as pd
import io
from scipy import stats
ctrl=u"""probegenes,sample1,sample2,sample3
1415777_at Pnliprp1,20,0.00,11
1415884_at Cela3b,47,0.00,100
1415805_at Clps,17,0.00,55
1115805_at Ckkk,77,10.00,5.5
"""
df_ctrl = pd.read_csv(io.StringIO(ctrl),index_col='probegenes')
test=u"""probegenes,sample1,sample2,sample3
1415777_at Pnliprp1,20.1,10.00,22.3
1415805_at Clps,7,3.00,1.5
1415884_at Cela3b,47,2.01,30"""
df_test = pd.read_csv(io.StringIO(test),index_col='probegenes')
他们看起来像这样:
In [35]: df_ctrl
Out[35]:
sample1 sample2 sample3
probegenes
1415777_at Pnliprp1 20 0 11.0
1415884_at Cela3b 47 0 100.0
1415805_at Clps 17 0 55.0
1115805_at Ckkk 77 10 5.5
In [36]: df_test
Out[36]:
sample1 sample2 sample3
probegenes
1415777_at Pnliprp1 20.1 10.00 22.3
1415805_at Clps 7.0 3.00 1.5
1415884_at Cela3b 47.0 2.01 30.0
我想:
- 获取共同
index
为DataFrame
- Reo同样地
DataFrame
。
因此,最后我得到两个新的DataFrame
:
new_df_ctrl
sample1 sample2 sample3
probegenes
1415884_at Cela3b 47 0 100.0
1415805_at Clps 17 0 55.0
1415777_at Pnliprp1 20 0 11.0
new_df_test
sample1 sample2 sample3
probegenes
1415884_at Cela3b 47.0 2.01 30.0
1415805_at Clps 7.0 3.00 1.5
1415777_at Pnliprp1 20.1 10.00 22.3