'DataFrame column contains characters that are not numbers - how to convert to integer?

I have the following Problem: I have a dataframe that looks like this:

A B

0 1 [5]

1 3 [1]

2 3 [118]

3 5 [34]

Now, I Need column B to only contain numbers, otherwise I can't work with the data. I already tried to use the replace-function and simply replace "[]" with "", but that didn't work out.

Is there any other way? Maybe I can convert the whole column to only keep the numbers as integers? That would be even better than just dropping the parenthesis.

I'm grateful for any help, I've been stuck with this for 2h now.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source