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

How to convert a sequence of letters into a list of numbers? Python Pandas

For example:
If we have a column in a data frame with the sequence: ‘ABCD’
How can we transform it into a list: [‘A’,’B’,’C’,’D’]
This would be done in a pandas dataframe.

Thank you!

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

>Solution :

You can just .map() the list() function to the series that has the string values like 'ABCD'.

For example:

from pandas import DataFrame

df = DataFrame(['ABCD', 'EFGH', 'IJKL'])
df[0] = df[0].map(list)

print(df)

Output:

              0
0  [A, B, C, D]
1  [E, F, G, H]
2  [I, J, K, L]
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