Karina Data Scientist
Python tipYou have a column of whole numbers. After a merge or fillna, suddenly they're floats with decimals.Standard integers can't hold missing values. One NaN forces the entire column to float64.To fix it - Use nullable integer dtypes (Int64) or fill before converting back.The key difference:int64 (lowercase) → Can't hold NaN, converts to float64Int64 (uppercase) → Nullable integer, stays integer with <NA>The rule:Need to keep missing values? Use Int64Missing = 0 makes sense? Use fillna(0).astype('int64')Always check dtypes after merges
6 days ago | [YT] | 20
Karina Data Scientist
Python tip
You have a column of whole numbers. After a merge or fillna, suddenly they're floats with decimals.
Standard integers can't hold missing values. One NaN forces the entire column to float64.
To fix it - Use nullable integer dtypes (Int64) or fill before converting back.
The key difference:
int64 (lowercase) → Can't hold NaN, converts to float64
Int64 (uppercase) → Nullable integer, stays integer with <NA>
The rule:
Need to keep missing values? Use Int64
Missing = 0 makes sense? Use fillna(0).astype('int64')
Always check dtypes after merges
6 days ago | [YT] | 20