0

I somehow have a strange conversion problem in python. I have an object column which I want to convert to an int column to save some memory space.

I run the following command:

df['Number'] = df['IntC'].astype(int)

and somehow for some rows it ends up like this:

IntC               Number
233004885002       -188830000475
233048850003       -195883838200

What is happening here? I would expect this output:

IntC               Number
233004885002       233004885002 
233048850003       233048850003
1
  • 2
    works well for me. you can also try .astype('int64'). Commented May 7, 2020 at 14:41

2 Answers 2

1

If convert object to int , why not do factor

df['Number'] = df.IntC.factorize()[0]
Sign up to request clarification or add additional context in comments.

1 Comment

somehow it gives the same error, `astype('int64') works
0

Using Lambda function is a much-generalized option

df['Number'] = df.IntC.apply(lambda c: int(c))

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.