繁体   English   中英

从in64数据类型返回中获取不同的对象

[英]Get different objects out of in64 data type return

作为一个大功能的一部分,我坚持最后一行。 我应该得到(pandas)数据帧中最高(很少)值的行和列名称。 因此,我将其拆开,对其进行分类并打印最后两行。 使用:

df2=zerotriangle_frame.unstack()
sorted_df = df2.sort_values(inplace=True)
x = df2[-2:]

这导致:

seq_6120  seq_1761    34
seq_4833  seq_1761    37
dtype: int64

这很好(分别是:seq_4833和seq_1761是类似于最高值的行和列名称(在上下文中的最高序列simmilarity),seq_6120和seq_1761类似于第二个最高值......)但我想以某种方式格式化此输出以便我可以使用打印部分中的不同部分。 例如:

print("sequenc {0} and sequence {1} got the highest simmilarity value:{2}".format(a, b, c))

其中a,b和c应分别为seq_4833,seq_1761和37 ......如果结果是列表或元组,我可以拆分它,但现在我卡住了。

PS:此外,当值(示例中的34和37)相同时,我应该打印一些特定的错误消息(比如'超过1对具有相同同义性的序列')。

假设df2是您的最终数据帧,那么您可以只过滤所有等于最大值的行,并编写if语句来生成输出。

# assuming df2 is a dataframe with columns a,b,c
df3 = df2[df2.c == df2.c.max()]

if len(df3) == 1:
    print("sequence {0} and sequence {1} got the highest simmilarity value:{2}".format(df3.a.values[0], df3.b.values[0], df3.c.values[0]))
else:
    for i, row in df3.iterrows():
        print("sequence {0} and sequence {1} got the same simmilarity value:{2}".format(row.a, row.b, row.c))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM