separating a string that contains decimals and words and creating columns from the unique values in that string using Pandas/Python
Use Series.str.extractall
with capturing groups to get the word and the numeric value (allowing for parenthesis to indicate negative values), which are separated by a colon. Then, pivot
this DataFrame into the appropriate format. Since the extract pairs labels with values, they can even occur out of order in separate strings, like in the sample I created below.
Sample data
import pandas as pd
s = pd.Series(['Storage:9.22Checkoff:6.90InElevation:0.00OutCharge:0.00Freightother:0.00',
'Checkoff:6.97Storage:19.22InElevation:0.00OutCharge:10.00Freightother:56.55',
'Checkoff:(2.00)Storage:19.22InElevation:0.00OutCharge:10.00Freightother:56.55'])
Code
df = s.str.extractall(r'(.*?):([\(\)0-9.]+)').reset_index()
df = df.pivot(index='level_0', columns=0, values=1).rename_axis(index=None, columns=None)
print(df)
# Checkoff Freightother InElevation OutCharge Storage
#0 6.90 0.00 0.00 0.00 9.22
#1 6.97 56.55 0.00 10.00 19.22
#2 (2.00) 56.55 0.00 10.00 19.22