Python
#27

Handle Infinite Values and Division by Zero in Pandas

Easy
Interview Question #27

When dividing revenue by ad spend where spend is 0, Pandas produces `inf`. Detect all infinite values in the DataFrame and replace them with `NaN`.

Input Table: df
2 rows preview
revenuead_spend
10000
50001000
Expected Output Structure2 rows
roas
NULL
5
Interview Context

Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.

Python 3.10 (Pandas)
Environment Ready

Starting the real Python + pandas runtime (one-time download)…

Chat with us