I'm running a python script, where I have to convert a string column from a pandas df
to int
, using the astype(int)
method. However, I get this following error:
"Python int too large to convert to C long"
My strings are all numbers in string format, up to 15 characters. Is there a way to convert this column to int type without this popping this error?
You need to use .astype('int64')
import pandas as pd
df = pd.DataFrame({'test': ['999999999999999','111111111111111']})
df['int'] = df['test'].astype('int64')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With