Skip to content Skip to sidebar Skip to footer

Unwanted Type Conversion In Pandas.dataframe.update

Is there any reason why pandas changes the type of columns from int to float in update, and can I prevent it from doing it? Here is some example code of the problem import pandas a

Solution 1:

here's the reason for this: since you are effectively masking certain values on a column and replace them (with your updates), some values could become `nan

in an integer array this is impossible, so numeric dtypes are apriori converted to float (for efficiency), as checking first is more expensive that doing this

a change of dtype back is possible...just not in the code right now, therefor this a bug (a bit non-trivial to fix though): github.com/pydata/pandas/issues/4094

Post a Comment for "Unwanted Type Conversion In Pandas.dataframe.update"