Home > Back-end >  convert int64 to int32 in pandas.to_numeric()
convert int64 to int32 in pandas.to_numeric()

Time:08-05

I have a data frame with a column with dtype(int64) and I want convert it to int32.
when I run code below, I get dtype(int8) type but i want get int32

pd.to_numeric(x, downcast="integer")

how do i do it!

CodePudding user response:

Try this,

df['col'].astype(np.int32)

astype doc link: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.astype.html

Please have a look at numpy datatype docs: https://numpy.org/doc/stable/user/basics.types.html

  • Related