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

Question:

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!

Asked By: Isaoud

||

Answers:

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]
Answered By: Grismar
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.