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

Issue

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')

Answered By – ALollz

Answer Checked By – Cary Denson (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *