gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
given for index, row in df.iterrows(): check if all row is empty
- User
given for index, row in df.iterrows(): check if all row is empty
- Assistant
To check if all values in a row are empty (e.g.,
NaN, empty strings, or None) inside afor index, row in df.iterrows()loop, you can do something like this:pythonimport pandas as pd import numpy as np # Example DataFrame df = pd.DataFrame({ 'A': [np.nan, '', 1], 'B': [None, '', 2], 'C': [np.nan, np.nan, 3] }) for index, row in df.iterrows(): # Option 1: Check if all values are NaN or None if row.isnull().all(): print(f"Row {index} is all NaN or None") # Option 2: Check if all values are empty strings or NaN/None # Convert row to str and strip spaces, then check if all are empty strings elif all((pd.isnull(x) or str(x).strip() == '') for x in row): print(f"Row {index} is all empty or NaN")