【发布时间】:2022-11-13 05:00:50
【问题描述】:
我正在尝试验证列表的元素是否包含在 Pandas 的 DataFrame (DF) 中。
这是我到目前为止的代码:
from pathlib import Path
data = pd.read_excel(r'/home/darteagam/diploma/bert/files/codon_positions.xlsx')
df = pd.DataFrame(data,columns=['position','codon','aminoacid'])
print("DataFrame Loaded!")
#print(df)
# reading the files
with open("/home/darteagam/diploma/bert/files/bert_aa_example.txt", "r") as f1, open("/home/darteagam/diploma/bert/files/bert_nn_example.txt", "r") as f2:
#with open("/home/darteagam/diploma/bert/files/bert_nn_example.txt", "r") as f2:
print('AA in 31 position:')
for aa in f1:
prot_seq = list(aa)
lp = len(prot_seq)
position_aa = prot_seq[30:31]
#print(prot_seq)
position_aa = list(aa[30:31]) # verifiying the 31 position
print(position_aa)
#print(len(position_aa))
#print(aa)
#print('Nucleotide sequences')
for nn in f2:
nuc_seq = nn
#print(nuc_seq)
x=3
spl=[nuc_seq[y-x:y] for y in range(x, len(nuc_seq)+x,x)]
pos_cod = spl[30:31]
list_codons = (list(pos_cod))
print(list_codons)
#print(len(list_codons))
#print(spl)
列表的输出:
['ATC']
['AAC']
['ACC']
['TTT']
['GTC']
['CTC']
DF的输出:
position codon aminoacid
0 1 GCT A
1 2 GCC A
2 3 GCA A
3 4 GCG A
4 5 CGT R
.. ... ... ...
56 57 TAC Y
57 58 GTT V
58 59 GTC V
59 60 GTA V
60 61 GTG V
我想验证输出中的列表是否包含在 DF 的列密码子中,并获取该元素在 DF 中的位置。
任何建议都会很有用,因为这是我第一次使用 Pandas。
【问题讨论】:
标签: python pandas list dataframe machine-learning