我有一个多索引的熊猫数据框,看起来像这样(片段):
Smad3_pS423/425_customer 0 1 0.664263
2 0.209911
3 0.099809
5 1 0.059652
2 0.190174
3 0.138850
a-Tubulin 0 1 0.072436
2 0.068282
3 0.087989
5 1 0.083960
2 0.076102
3 0.068119
df.index的输出是(labels
为了查看目的,该位被缩短了):
MultiIndex(levels=[[u'Customer_Col1A2', u'Smad2_pS465/467 customer', u'Smad3_pS423/425_customer', u'Smad4_customer', u'Smad7_customer', u'a-Tubulin'], [u'0', u'10', u'120', u'180', u'20', u'240', u'30', u'300', u'45', u'5', u'60', u'90'], [u'1', u'2', u'3']],
labels=[[2, 2, 2, 2, 2, 2, 2, ... more_labels...]],
names=[u'Antibody', u'Time', u'Repeats'])
我的问题是,a-tubulin
按Smad3_pS423/425_customer
条目划分数据条目的最佳方法是什么?
一种麻烦的方法是:
ab=[]
for i in self.data.index.get_level_values('Antibody'):
ab.append(i)
antibodies= list(set(ab))
for i in antibodies:
print self.data.loc[i]/self.HK
但这似乎不是pandas
实现此目的的方式。有人知道这样做更简单吗?(我怀疑pandas
可能内置了一个班轮来执行此操作)。谢谢
怎么样:
df.ix['a-Tubulin'] / df.ix['Smad3_pS423/425_customer']
3
1 2
0 1 0.109047
2 0.325290
3 0.881574
5 1 1.407497
2 0.400170
3 0.490594
这是我使用的df数据框,您可以加载 df = pd.read_clipboard(sep=',', index_col=[0,1,2])
0,1,2,3
Smad3_pS423/425_customer,0,1,0.664263
Smad3_pS423/425_customer,0,2,0.20991100000000001
Smad3_pS423/425_customer,0,3,0.09980900000000001
Smad3_pS423/425_customer,5,1,0.059652
Smad3_pS423/425_customer,5,2,0.190174
Smad3_pS423/425_customer,5,3,0.13885
a-Tubulin,0,1,0.072436
a-Tubulin,0,2,0.06828200000000001
a-Tubulin,0,3,0.087989
a-Tubulin,5,1,0.08396
a-Tubulin,5,2,0.076102
a-Tubulin,5,3,0.068119
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句