In a BCG client analytics workflow, raw records often contain missing values. Implement a function that cleans a 2D dataset by either dropping rows with too many missing entries or filling missing entries using a provided default value.
A missing entry is represented by None. Given a list of rows, an integer max_missing, and a fill_value, return a new list of rows after applying these rules:
max_missing missing entries, discard the entire row.None in that row with fill_value.records as a list of lists, max_missing as an integer, and fill_value as an integerExample 1
records = [[1, None, 3], [None, None, 5], [7, 8, 9]], max_missing = 1, fill_value = 0[[1, 0, 3], [7, 8, 9]]0.Example 2
records = [[None], [4], [None, None]], max_missing = 1, fill_value = -1[[-1], [4]]1 <= len(records) <= 10^41 <= len(records[i]) <= 10^3fill_value are integersNonerecords = [[1, None, 3], [None, None, 5], [7, 8, 9]], max_missing = 1, fill_value = 0Output[[1, 0, 3], [7, 8, 9]]WhyThe first row has one missing value and is filled. The second row has two missing values and is removed. The third row is unchanged.records = [[None], [4], [None, None]], max_missing = 1, fill_value = -1Output[[-1], [4]]WhyThe first row is kept because it has exactly one missing value. The last row is dropped because it exceeds the threshold.1 <= len(records) <= 10^41 <= len(records[i]) <= 10^3-10^9 <= records[i][j] <= 10^9 for non-missing values-10^9 <= fill_value <= 10^9Missing values are represented only by None0 <= max_missing <= len(records[i])def clean_missing_records(records, max_missing, fill_value):