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!
CodePudding user response:
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]