Data Cleaning: Dedup, Fill, Cast

mediumpandas_manipulation

A common data-cleaning pipeline: remove duplicates, fill missing values, fix type inconsistencies. Implement three functions.

drop_dup_ids(df, id_col) Remove duplicate rows based on id_col, keeping the first occurrence.

fill_mean(df, col) Return a copy of df with NaN in col replaced by the column's mean.

cast_col(df, col, dtype) Return a copy of df with col cast to dtype (e.g. float).

None of the three functions should mutate the input DataFrame.

Your solution

Edit drop_dup_ids and run the real pytest suite in your browser — no install required. Your code is saved locally.

⌘/Ctrl + ↵

Loading the Python runtime (first run only)…

Hints

Hint 1

drop_duplicates(subset=col) keeps the first occurrence of each unique value in col.

Hint 2

fillna(series.mean()) replaces NaN with the mean computed from non-missing values.

Hint 3

astype(float) converts the whole column — strings like '5.7' become 5.7.

Hint 4

Always work on a copy (df.copy()) to avoid mutating the caller's data.