Search code examples
pythonpandasnumpy

Int too large to convert to C long while doing .astype(int)


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?


Solution

  • You need to use .astype('int64')

    import pandas as pd
    df = pd.DataFrame({'test': ['999999999999999','111111111111111']})
    df['int'] = df['test'].astype('int64')