proomt

Search

Search posts, papers, and topics

All posts

Lerner Consulting BlogReuven Lerner1 min readintro

np.nan in Pandas: Why missing values break comparisons

Summary

The post explains that np.nan is a special floating‑point value that propagates through arithmetic and never compares equal, even to itself. It shows how this breaks naïve equality checks in pandas and suggests using pandas' isna/notna utilities instead.

  • np.nan is a float that propagates through arithmetic operations, yielding nan for any calculation involving it.
  • Comparisons with np.nan always return False, including np.nan == np.nan.
  • Pandas' standard equality checks (==) will treat rows with nan as unequal, which can break joins, filters, and deduplication.
  • Use pandas.isna() or pandas.notna() to reliably detect missing values instead of == or != operators.

Anyone cleaning or analyzing data with pandas needs to handle nan correctly, or they’ll get silent bugs in filters, joins, and aggregations.

5/10

Related reading

  1. Quiz: Introduction to pandas

    Real Python offers a 7‑question interactive quiz covering basic pandas tasks like pulling HTML tables, saving CSVs, DataFrame basics, and method chaining. The page provides only the quiz prompt without explanatory content.

    Real Pythonrealpython.com1 min
  2. The Shadows Lurking in the Equations – Underwater Islands

    The article introduces FuzzyGraph, a web tool that visualizes equations as error heatmaps (fuzzy/non‑binary mode) instead of the classic binary “exact‑equals” plots. By showing regions of high error (black‑hole shadows) and low error (underwater islands), the author argues that fuzzy graphs reveal mathematical features invisible to conventional graphing tools.

    Hacker News front pagegods.art4 minHN7013
  3. Why Does an NPM Math Library Need an Encrypted Loader?

    SafeDep discovered that several npm packages masquerading as mathjs contain an encrypted loader that only activates when a caller passes a particular matrix to the LU solver, using the matrix’s lower‑triangular factor as the decryption password. The loader decrypts and executes a multi‑stage remote‑access implant that talks to Slack, Telegram and a blockchain contract, and the same technique is r…

    Hacker News front pagesafedep.io10 minHN9627