0

Sorry to be asking a question again but this isn't making sense to me

I'm trying to change the datatype of my column into an int and did the following:

df.Age.astype(object).astype(int)

this works and it looks like it's changed to an int but then if I do

df.Age 

it is then appearing as an object data type? How I can make the change permanent?

lross12
  • 73
  • 6

1 Answers1

3

You have to assign with the serie:

df.Age = df.Age.astype(int)

Consider also:

df["Age"] = pd.to_numeric(df["Age"])

Reference: Change data type of columns in Pandas

briba
  • 2,857
  • 2
  • 31
  • 59
  • Thank you that's got it working, and well the aystype way is what I had been reading online. Never actually seen the to_numeric way – lross12 Apr 29 '20 at 16:14