Home > Back-end >  How to convert object data type into int64 in python?
How to convert object data type into int64 in python?

Time:03-18

I have a dataset and it has one variable as object data type, i have to convert it to int64 type.

dataframe head

dataframe info

CodePudding user response:

You can try by doing df["Bare Nuclei"].astype(np.int64) but as far as I can see the problem is something else. Pandas first reads all the data to best estimate the data type for each column, then only makes the data frame. So, there must be some entries in the data frame which are not integer types, i.e., they may contain some letters. In that case, also typecasting should give an error. So you need to remove those entries before successfully making the table integer.

  • Related