I have dataframe from pandas
. I am not sure how to start extracting the information.
The data in the column is like this:
->Company A 100->Company B 60->Company C 80-> Company D
->Company A 100->Company B 53.1->Company C 82.2->Company D 100-> Company G
->Company A 100->Company B 23-> Company D
etc...
The information of the companies are not important, only the last number in each item.
I want to extract the number before the last ->
and paste it into another column.
For example, extract 80
, 100
, and 23
, respectively.
80
100
23
I have this
import re
text = '->Company A 100->Company B 60->Company C 80-> Company D'
re.findall(r'\d+', text)[-1]
which gives the right output '80'
But when I do it for a df
re.findall(r'\d+', df['ColumnName'])[-1]
I get: TypeError: expected string or bytes-like object