2

I have the following column in a DF. How could I convert this column into a float(13,5) with 5 decimals.String length is always 18 characters. As a workaround , I have used string split function and joined return values.

df=pd.DataFrame(['+00000030454360000','-00000030734250000','-00000004643685000'],columns=['qty'])
print df.qty.str[:13]+'.'+df.qty.str[13:]

Expected Output

                    0
0  +304543.6
1  -307342.5
2  -46436.85
2
  • in the question you stated that you need float(13,5), but in the desired data set you have strings. So do you need modified strings or floats? Commented Feb 6, 2017 at 18:30
  • 1
    @ MaxU Just realized the mistake:) I need float value Commented Feb 6, 2017 at 18:34

1 Answer 1

1

Try this:

In [23]: pd.to_numeric(df.qty, errors='coerce') / 10**5
Out[23]:
0    304543.60
1   -307342.50
2    -46436.85
Name: qty, dtype: float64
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @MaxU.. I was expecting an answer from you
@Shijo, glad i could help :-)

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.