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 integersNone