Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Process string in Pandas Dataframe rows to comma-delimitered chars

I have a dataframe, with data in each row as such.

MKEYGEDLK

How can I process the sequence strings in each row, such that the format will be as such?

[M, K, E, Y, G, E, D, L, K]

I tried

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

get_seq_str = ','.join(test_df.loc[0]['seq_1'])
arr.append(get_seq_str)

However, when I append it to the dataframe, there is a single quotation mark at the start and end of each string, which I do not want.

['M, K, E, Y, G, E, D, L, K']

How can I strip the single quotation marks?

>Solution :

IIUC, you can try apply list to string value

df['col_list'] = df['col'].apply(list)
print(df)

         col                     col_list
0  MKEYGEDLK  [M, K, E, Y, G, E, D, L, K]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading