我有一個(gè)數(shù)據(jù)框如下Genes s1 s2 s3 s4 s5 s6 s7 s8 s9 s10AB1 0 0 0 0 0 0 0 0 0 0GB2 1 0 0 25 0 10 0 0 5 0AB3 0 0 0 0 0 0 0 0 0 0AB4 0 0 0 0 0 0 0 0 0 0hB5 0 0 50 0 66 0 88 15 0 0OB6 0 0 0 0 0 0 0 0 0 0AB7 25 40 30 45 44 15 0 80 85 10UB8 0 0 0 0 0 0 0 0 0 0YB9 0 1 0 5 1 0 5 4 2 2AB10 0 0 0 0 0 0 0 0 0 0TB11 0 0 0 0 0 0 0 0 0 0AB12 0 0 0 0 0 0 0 0 0 0我想過濾至少4個(gè)樣本中計(jì)數(shù)大于10的基因預(yù)期的輸出是Genes s1 s2 s3 s4 s5 s6 s7 s8 s9 s10hB5 0 0 50 0 66 0 88 15 0 0AB7 25 40 30 45 44 15 0 80 85 10我嘗試了以下代碼,但沒有給出預(yù)期的結(jié)果import pandas as pdcounts = pd.read_excel("rna.xlsx")counts = counts[(counts > 0).sum(axis=1) >= 4]counts.to_csv("output.tsv", sep="\t", header=False)
1 回答

一只甜甜圈
TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超5個(gè)贊
比較值 by10而不是 by 0,如果第一列未轉(zhuǎn)換為索引 add index_col=0:
counts = pd.read_excel("rna.xlsx",
index_col=0)
counts = counts[(counts > 10).sum(axis=1) >= 4]
print (counts)
s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
Genes
hB5 0 0 50 0 66 0 88 15 0 0
AB7 25 40 30 45 44 15 0 80 85 10
添加回答
舉報(bào)
0/150
提交
取消