Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 847
Lucas Pelin Avatar asked Feb 04 '23 01:02

Lucas Pelin


1 Answers

You need to use .astype('int64')

import pandas as pd
df = pd.DataFrame({'test': ['999999999999999','111111111111111']})
df['int'] = df['test'].astype('int64')
like image 141
ALollz Avatar answered Feb 06 '23 15:02

ALollz