我有一个df,例如:
cluster_name qseqid sseqid pident length qstart qend
cluster_000001 seq1 YP_009416.1 57.4 61 0 182
cluster_000001 seq2 NP_592.1 24.1 349 68 1081
cluster_000002 seq4 YP_009695.1 25.7 249 0 725
cluster_000002 seq3 YP_009695.1 25.8 291 0 818
cluster_000003 seq8 YP_002675.1 25.8 291 0 818
在每个群集中,我想对sseqid的每个值做一些事情,换句话说,我应该是这样的:
for cluster in blast.groupby('cluster_name'):
for row in blast['sseqid']:
print(row)
print("ok")
,结果应为:
YP_009416.1
NP_592.1
ok
YP_009695.1
YP_009695.1
ok
YP_002675.1
但是它不起作用。
答案 0 :(得分:0)
尝试:
for _, cluster in blast.groupby('cluster_name'):
for row in cluster['sseqid']:
print(row)
print("ok")