John Mayne
John Mayne

Reputation: 277

How to transform a column of string into columns of a single char? Python Pandas

I am dealing with DNA sequencing data, and each column looks something like "ACCGTGC". I would like to transform this into several columns, where each column contains only one char. How to do this in Python pandas?

Upvotes: 1

Views: 48

Answers (1)

jezrael
jezrael

Reputation: 863256

For performance convert values to lists and pass to DataFrame constructor:

df1 = pd.DataFrame([list(x) for x in df['col']], index=df.index)

If need add to original:

df = df.join(df1)

Upvotes: 1

Related Questions