嗨,我知道怎么用
`df2.loc[df2[2]=="gene"]` for instance
但是可以说我从中得到了
0 1 2 3 4 5 6 7 8
0 NW_011626968.1 AUGUSTUS gene 1671821 1675615 0.04 - . g1
7 NW_011626968.1 AUGUSTUS gene 1677196 1679599 0.13 + . g2
我还如何添加col2和3的信息以匹配特定值并仅获得第7行?
我尝试过:
df2.loc[df2[2]=="gene"] & df2.loc[df2[3]=="1677196"] & df2.loc[df2[4]=="1679599"]
答案 0 :(得分:1)
这里还添加了必要的链掩码,而不是经过过滤的行,()
因为操作符的优先级而被添加:
#if columns are filled by strings
#df3 = df2[(df2[2]=="gene") & (df2[3]=="1677196") & (df2[4]=="1679599")]
#if columns are filled by numbers
df3 = df2[(df2[2]=="gene") & (df2[3]==1677196) & (df2[4]==1679599)]
print (df3)
0 1 2 3 4 5 6 7 8
7 NW_011626968.1 AUGUSTUS gene 1677196 1679599 0.13 + . g2