unwanted type conversion in pandas.DataFrame.update

前端 未结 1 1735
萌比男神i
萌比男神i 2021-01-18 06:39

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

相关标签:
1条回答
  • 2021-01-18 07:04

    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

    0 讨论(0)
提交回复
热议问题