Jun-04-2018, 04:33 PM
Hi,
I have below dataFrame and I want search and take the numeric value left side to specified substring.
My data:
I tried above, but I could not be able to get in a single line what I want.
I have below dataFrame and I want search and take the numeric value left side to specified substring.
My data:
df2 = pd.DataFramedf = pd.DataFrame({'ids': ['AA-120amp', 'BA+250A-52amp', 'AA-5623amp','CD']}) df2[['df2','rank']] = df2['ids'].str.split('-',expand=True) print (df2: (output) ids df2 allele rank 0 AA-120amp AA 120amp 120amp 1 BA+250A-52amp BA+250A 52amp 52amp 2 AA-5623amp AA 5623amp 5623amp 3 CD CD None None my desired output is: ids df2 allele rank 0 AA-120amp AA 120amp 120 1 BA+250A-52amp BA+250A 52amp 52 2 AA-5623amp AA 5623amp 5623I want to split the column at amp, and print numerical value left side to amp. If no amp exists in any row, just print None.
I tried above, but I could not be able to get in a single line what I want.