I have the following dataframe where I want to split the Col2 into multiple columns:
Input DataFrame:
>>> mydf= pd.DataFrame({'Col1':['AA','AB','AAC'], 'Col2':['AN||Ind(0.9)','LN||RED(8.9)','RN||RED(9.8)'], 'Col3':['log1','log2','log3']})
>>> mydf
Col1 Col2 Col3
0 AA AN||Ind(0.9) log1
1 AB LN||RED(8.9) log2
2 AAC RN||RED(9.8) log3
Desired DataFrame:
Col1 Col2 Col3 Col4 Col5
0 AA AN log1 Ind 0.9
1 AB LN log2 RED 8.9
2 AAC RN log3 RED 9.8
I started with Apply but the following will take a good few steps. Any shortcut?
mydf['Col4']=mydf['Col2'].apply(lambda x: str(x).split('||')[0])
Also little confused why the following throws a valuerror:
mydf['Col2'].str.split('||', expand=True)
ValueError: split() requires a non-empty pattern match.