Python Pandas Series Alignment and NaN Values

🐍 Did you know that in Python, NaN is always a float. This has some interesting consequences when working with Series in Pandas: x = pd.Series([10, 20], index=["a","b"]) y = pd.Series([10, 30, 5], index=["a","b","c"]) print((x + y).dtype) # float64 Pandas aligns Series by index, so missing values like "c" in x are treated as NaN, which can only be a float, causing all numbers in the result to be upcast to float64. #Python #Pandas #PythonTips #Coding

  • text

To view or add a comment, sign in

Explore content categories