1

I have an array.

array(['+$35.00', '="-$5.00"', '+$42.24', '+$10.56', '="-$20.00"',`
       '+$60.00', '="-$10.00"', '+$21.00', '+$18.50', '+$10.00',
       '+$19.00', '+$34.40', 0], dtype=object)

I know this has been covered many times but I cant seem to convert column in pandas to a float.

1
  • 1
    Where does this array come from? Maybe you can begin to convert it better already at an earlier stage? What's the original input? And what do = in this data mean? Commented Jul 20, 2022 at 9:00

1 Answer 1

1

Assuming a the array, you can use:

# convert the array to Series
s = pd.Series(a)
# extract float representation from strings, convert to numeric
# fill with values that were already floats
s = pd.to_numeric(s.str.extract(r'(\d+(?:\.\d+)?)', expand=False)).fillna(s)

output:

0     35.00
1      5.00
2     42.24
3     10.56
4     20.00
5     60.00
6     10.00
7     21.00
8     18.50
9     10.00
10    19.00
11    34.40
12     0.00
dtype: float64
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.