0

I have a pandas dataframe df and one of the columns df['x'] contains strings of length 100, each string of the form 'ABBABBBABBAABAABABBAAABAAAA...'

How would I go about splitting this 1 column into 100 different columns, each containing only 1 character from the original string?

1 Answer 1

1

You can use str.split:

df['x'].str.split('',expand=True).iloc[:,1:-1]

or str.extractall with unstack:

df['x'].str.extractall('(.)')[0].unstack()
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.