DNA sequences in FASTA format look like:


I am trying to convert them into one-hot encoded data in a Pandas dataframe so that I can use various neural networks to analyze them. This has probably been done many times. Can someone point me to references or Python packages for it?


1 Answer 1


I am not sure about any python package but you can simply do integer encoding using labelencoder() and then do one-hot encoding.

label_encoder = LabelEncoder()
integer_encoded_seq = label_encoder.fit_transform(seq)    
onehot_encoder = OneHotEncoder(sparse=False)
integer_encoded_seq = integer_encoded_seq.reshape(len(integer_encoded_seq), 1)
onehot_encoded_seq = onehot_encoder.fit_transform(integer_encoded_seq)

Refer this.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.