How do i set my INT values from int32 to int64 using pandas

Viewed 2537

I have a question about pandas to_numeric. I'm trying to cast a Colum from a float to INT, however df.info is stating my Colum is being cast to a int32.

First question, I thought the default INT value using to_numeric is int64? Source

to_numeric(arg, errors='raise', downcast=None) Convert argument to a numeric type.

The default return dtype is float64 or int64 depending on the data supplied. Use the downcast parameter to obtain other dtypes.

Second Question, How do I change it from int32 to int 64 as a MPRN is more the ten numbers and I'm getting negative values in my Dataframe now.

My code example

   import pandas as pd

  df['MPRN'] = pd.to_numeric(df['MPRN'], errors="coerce").fillna(0).astype(int).to_frame()

df.info()

MPRN 387 non-null int32

1 Answers

You can use

df['MPRN'] = pd.to_numeric(df['MPRN'], errors="coerce").fillna(0).astype('int64')
Related