The first step of exploratory data analysis is a profile of every column: what type it is, how much is missing, how many distinct values it has, its basic statistics and anything that looks wrong. Write the function that produces that profile for a pandas DataFrame.
Implement profile_dataframe(df) returning
{"n_rows": int, "n_cols": int, "duplicate_rows": int, "columns": {name: profile, ...}}, with columns in DataFrame order. duplicate_rows counts rows identical to an earlier row.
Every column profile has:
"kind": "boolean" for a pandas bool dtype, "numeric" for any other numeric dtype, otherwise "categorical"."missing_pct": percentage of missing values, rounded to 2 decimals."n_unique": number of distinct non-missing values."flags": list, in this order, of those that apply:
"constant": n_unique <= 1"high_missing": missing_pct > 50"high_cardinality": categorical, at least 5 non-missing values and n_unique > 0.9 * (non-missing count)"outliers": numeric and n_outliers > 0Numeric columns also have "mean", "std" (sample, ddof=1), "min", "median", "max" as floats rounded to 4, and "n_outliers": the number of non-missing values below or above , with quartiles from pandas' default (linear) quantile. Statistics are None when there are no non-missing values (and "std" is None with fewer than 2); n_outliers is then 0.
Boolean and categorical columns also have "top" (the most frequent non-missing value; ties go to the value that appears first in the column) and "top_freq" (its count); both None/0 when the column is all missing. Return "top" as a plain Python value.