Search code examples
pythonpandasdictionaryfillna

How to keep the same dict value while filling the nans in pandas


Assume we have the dict having the median values of the features: infereddict = {sepalwidth : -0.03999432052319804, sepalheight :-0.08741807979521529, petalwitdh: -0.049475134763957505}

while we fill the nans in datafarame with the dict , it changes the value and gives below output sepalwidth -3.999432e-02 sepalheight -8.741808e-02 petalwitdh -4.947513e-02

Seems its ignoring the zeros, I need the exact same values from dict to fill the nans, how can we get it?


Solution

  • Pandas is displaying the numbers in scientific notation. The values are equal to each other, it's just a different way of displaying numbers.

    Some examples of comparing the two and converting between two formats

    >>> # You can directly check that they're equal to each other
    >>> -0.039994 == -3.9994e-2
    True
    >>> # Type in a number in scientific notation to see its decimal counterpart
    >>> -8.741808e-02
    -0.08741808
    >>> # Use f-strings and ':e' to view a decimal in scientific notation format
    >>> f"{-0.04947513:e}"
    -4.947513e-02