Home > Mobile >  Split string in pandas dataframe into individual columns - no delimiter
Split string in pandas dataframe into individual columns - no delimiter

Time:08-27

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?

CodePudding user response:

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()
  • Related