Reputation: 1690
I have a dataframe with column 'A' as a string. Within 'A' there are values like name1-L89783 nametwo-L33009
I would like to make a new column 'B' such that the '-Lxxxx' is removed and all that remains is 'name1' and 'nametwo'.
Upvotes: 0
Views: 58
Reputation: 169274
Initialize DataFrame
.
df = pd.DataFrame(['name1-L89783','nametwo-L33009'],columns=['A',])
>>> df
A
0 name1-L89783
1 nametwo-L33009
Apply
function over rows and put the result in a new column.
df['B'] = df['A'].apply(lambda x: x.split('-')[0])
>>> df
A B
0 name1-L89783 name1
1 nametwo-L33009 nametwo
Upvotes: 1