I started my machine learning journey by deciding to explore recommender systems so that I can apply it in some of the projects for my company. Now, I am using Pandas for data analysis. The data set is the imdv movies data set. Here, I am trying to convert a pandas series object to int but it converts the series to float64.

Here is the screenshot:

enter image description here

'clean_ids' is the method that I am using to do this and you can see that 'id' changes to float64. Please help me with this.


1 Answer 1


Your code is correct. The problem is that you have NaN values in your id column and python interprets NaN as float. In your code any decimal values it encounters will be converted to integer but represented as $x.0$ due to presence on NaN values. See here for more.

As for a solution to your problem you can either drop the NaN values or use IntegerArray from pandas. It is currently experimental but suits yor problem.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.