Do the Repeats Matter?

Data with PythonHard+10 XP+10

Do the Repeats Matter?

A dataset has some rows that exactly repeat earlier rows. Before deciding whether to drop them, check if they actually change the answer you care about.

Task: write duplicate_check(column_names, rows, x, y). rows is a list of rows, each a list of values in the order of column_names. x and y are two of the column names.

Return a dictionary with:

  • "rows": how many rows there are
  • "duplicates": how many rows repeat an earlier row in every column (the first copy doesn't count)
  • "corr_all": the correlation between columns x and y using every row
  • "corr_clean": the same correlation after removing the repeated rows
  • "changed": True if the two correlations differ once rounded, otherwise False

Round both correlations to 2 decimal places. There are no missing values, and neither x nor y holds the same value in every row, before or after removing repeats.

Examples

column_names = ["alcohol", "acid", "quality"]
rows = [[9.4, 0.7, 5], [9.8, 0.88, 5], [9.4, 0.7, 5], [11.0, 0.5, 6], [12.5, 0.4, 7], [10.2, 0.6, 6]]
x = "alcohol"
y = "quality"
returns {'rows': 6, 'duplicates': 1, 'corr_all': 0.95, 'corr_clean': 0.95, 'changed': False}
column_names = ["hours", "score"]
rows = [[1, 50], [2, 60], [3, 65], [3, 65], [3, 65], [3, 65], [8, 70]]
x = "hours"
y = "score"
returns {'rows': 7, 'duplicates': 3, 'corr_all': 0.76, 'corr_clean': 0.85, 'changed': True}

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run