Prompt:

"Generate Python code to detect outliers in a dataset using the Modified Z-Score method, and return both the outlier rows and their indices."

Output:

import pandas as pd import numpy as np

Example data

data = {'values': [10, 12, 10, 14, 100, 11, 13, 12, 9, 200]} df = pd.DataFrame(data)

Detect outliers using Modified Z-Score

threshold = 3.5 median = np.median(df['values']) mad = np.median(np.abs(df['values'] - median)) modified_z_scores = 0.6745 * (df['values'] - median) / mad

Outliers

outliers = df[np.abs(modified_z_scores) > threshold] outlier_indices = outliers.index.tolist()

outliers, outlier_indices