I am working on an assignment of bioinfo.
I have converted from SMILES to the fingerprints(fp) for a group of molecules, and the data frame looks like this:
Then save the file to CSV file with to_csv .
Then reading the file with pd.read_csv
, the fingerprint changes into a string and looks like:
I replace the \n with empty space, , but the type is still a string.
I have used various methods:
ast.literal_eval(fp_df['fp'])
, then there is error: ValueError: malformed node or string:
, from the most upvoted answer here list(fp_df['fp'])
can't change the type of string [n.strip() for n in x]
doesn't work: And other methods have also been tried.
May I ask for your help on how to deal with it? Thanks in advance.
If your value looks like:
"[1 0 0 1 1 0]"
Then you can turn it into a list by:
values = value.lstrip("[").rstrip("]").split()
But the values will still be numeric strings, so you could cast to int
by:
values = [int(n) for n in value.lstrip("[").rstrip("]").split()]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.