Pandas TypeError: Fixing Column Name Spaces

A teammate recently ran into this Pandas error: TypeError: argument of type 'float' is not iterable The code looked correct: df.query("Overseas Collection in Crores == 0") The issue? The column name had spaces. query() evaluates the condition as a Python expression. Because the column name contained the word in, Pandas interpreted it as the membership operator. The Fix: df.query("`Overseas Collection in Crores` == 0") Or: df[df["Overseas Collection in Crores"] == 0] Clean column naming conventions help prevent subtle bugs. #Python #Pandas #DataEngineering

To view or add a comment, sign in

Explore content categories