I have a dataframe in which one of the columns contains a lengthy string which contains a lot of information which I need to break up into separate columns and add these to the dataframe. Its similar to this How to add a new column with multiple string contain conditions in python pandas other than using np.where? but I can't see how to adapt that.
I can create the empty columns but I don't know if the string can have elements extracted or if it can be separated into columns.
e.g. Line of data
0 Row 1 Ch475 Vi 17.0V BF27 Sclk 100ns 1in24 24segs
Desired output
RowNumber, Volts, Wfm, Sclk, Image, Segment
1 , 17 , BF27, 100 , 1in24, 24
Data
Comments Image
0 Row 1 Ch475 Vi 17.0V BF27 Sclk 100ns 1in24 24segs 0
1 Row 1 Ch475 Vi 17.0V BF27 Sclk 100ns 1in24 24segs 0
2 Row 1 Ch475 Vi 17.0V BF27 Sclk 100ns 1in24 24segs 0
3 Row 1 Ch475 Vi 17.0V BF27 Sclk 100ns 1in24 24segs 0
4 Row 1 Ch475 Vi 17.0V BF27 Sclk 100ns 1in24 24segs 0
.. ... ...
706 Row 2 Ch475 Vi 17.5V BF27 Sclk 100ns 1in24 24segs 0
707 Row 2 Ch475 Vi 17.5V BF27 Sclk 100ns 1in24 24segs 0
708 Row 2 Ch475 Vi 17.5V BF27 Sclk 100ns 1in24 24segs 0
709 Row 2 Ch475 Vi 17.5V BF27 Sclk 100ns 1in24 24segs 0
710 Row 2 Ch475 Vi 17.5V BF27 Sclk 100ns 1in24 24segs 0
Code
import pandas as pd
import numpy as np
path = "/Users/.../Desktop/tk_gui_grid/"
file = "orig_data.txt"
filepath = path+file
df = pd.read_csv(filepath, sep='\t', lineterminator='\r')
com = df.loc[:,['Comments']]
dfLen = len(com)
image = [0]*dfLen
com['Image'] = image
print(com)