Computer/코딩 개꿀팁
[꿀팁] rdkit Morgan Circular Fingerprint를 CSV등의 엑셀 파일로 export할때는 string형태로 변환한 뒤에 Export하자
벼랑끝과학자
2023. 7. 25. 21:27
안그러면 아래와 같은 형태로 export된다.
그리고 rdkit object에는 바로 str변환이 불가능한 것 같다.
다음처럼 .ToBitString()이라는 메서드로 한번 변환한 뒤에 str()으로 감싸서 변환해주자.
def bitvect_to_str(bitvect):
temp = str(bitvect.ToBitString())
temp = "\t".join(temp)
return temp
# Apply the function to convert the 'MorganFingerprint' column to a list of 0s and 1s
df['morgan_fp_r2'] = df['morgan_fp_r2'].apply(bitvect_to_str)
# Now the 'MorganFingerprint' column contains lists of 0s and 1s representing the fingerprint vectors
df
그러면 다음처럼 string 형태로 저장이 된다.
to_csv를 통해 엑셀 테이블로 저장도 제대로 된 것을 확인할 수 있다.