![]() |
VOOZH | about |
Given a NumPy array that may contain invalid values such as NaN, inf, or non-numeric entries, the task is to remove all rows that contain any such value and keep only rows with clean numerical data.
For Example:
Input: [[10.5, 22.5, 3.8], [41, nan, nan]]
Output: [[10.5, 22.5, 3.8]]
Let's explore different methods to remove rows which contains non numeric values in Python.
This method keeps only those rows where every element is a valid finite number. It works by detecting and removing rows that contain NaN, inf, or -inf in one check.
[[10.5 22.5 3.8]]
Explanation:
This method filters rows by checking if they contain any NaN. Rows without NaN are kept; rows with even one NaN are removed.
[[10.5 22.5 3.8]]
Explanation:
This method validates each row by checking whether all values are numeric. It works even when the array contains strings or Python objects.
[[10.5 22.5 3.8]]
Explanation: