I have a list that contains counts for different items as strings. Sometimes a restock is given in brackets. The list looks like this:
23
21 (+3)
32 (+14)
So there is always a space between the number and the brackets. To start of I've wrote a function that I apply over the Series. I've used the split-method two times to return only the first number:
splitted = item.split(" ")
splitted2 = splitted[0].split("+")
return int(splitted2[0])
This solution is kind of hacky already and on top of that, I am missing the restocks in brackets. Now I want to know, how I would possibly add both of the numbers together. I would therefore split the list one time so that I get this as a result:
['23']
['21', '(+3)']
Then I want to select only the list items, that have to values, get rid of the +
and ()
and add the first and the second value together. How would I do that?