# How can I use the return\_format unexpected\_index\_list to select row from a PandasDataSet

**URL:** <https://discourse.greatexpectations.io/t/how-can-i-use-the-return-format-unexpected-index-list-to-select-row-from-a-pandasdataset/70>\
**Category:** Archive\
**Created:** [March 6, 2020, 10:46pm UTC](https://discourse.greatexpectations.io/t/how-can-i-use-the-return-format-unexpected-index-list-to-select-row-from-a-pandasdataset/70 "2020-03-06T22:46:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mabloq](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@mabloq](https://discourse.greatexpectations.io/u/mabloq)\
**Post date:** [March 6, 2020, 10:46pm UTC](https://discourse.greatexpectations.io/t/how-can-i-use-the-return-format-unexpected-index-list-to-select-row-from-a-pandasdataset/70/1 "2020-03-06T22:46:26Z")

</div>

Im looking to provide unexpected index list as a parameter for the next task in my data pipeline in airflow or dagster.

---

<div class="post-metadata">

**Author:** ![abegong](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@abegong](https://discourse.greatexpectations.io/u/abegong)\
**Post date:** [March 6, 2020, 10:52pm UTC](https://discourse.greatexpectations.io/t/how-can-i-use-the-return-format-unexpected-index-list-to-select-row-from-a-pandasdataset/70/2 "2020-03-06T22:52:45Z")

</div>

Here’s a toy example that fetches the list of unexpected rows from a PandasDataAsset.

```auto
import great_expectations as ge
import pandas as pd

```

```auto
df = pd.DataFrame({
    "x": [0,1,2,3,4],
    "y": list("abcde")
})
ge_df = ge.from_pandas(df)

expectation_suite = ge.core.ExpectationSuite(**{
  "expectation_suite_name": "default",
  "expectations": [
    {
      "expectation_type": "expect_column_values_to_be_between",
      "kwargs": {
        "column": "x",
        "min_value": 1,
        "max_value": 3
      },
      "meta": {}
    }
  ],
})

```

```auto
result = ge_df.validate(expectation_suite, result_format="COMPLETE")
unexpected_indexes = result.results[0].result["unexpected_index_list"]

print(unexpected_indexes)
>> [0, 4]

```

```auto
failed_rows_df = df.ix[unexpected_indexes]
print(failed_rows_df)
>>>
   x y
0 0 a
4 4 e

```

This example uses a single expectation. With a little more work, you could aggregate the bad rows across multiple expectations.

---

<div class="post-metadata">

**Author:** ![accortdr](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.greatexpectations.io/accortdr/32/128_2.png) [@accortdr](https://discourse.greatexpectations.io/u/accortdr)\
**Post date:** [May 24, 2021, 11:37pm UTC](https://discourse.greatexpectations.io/t/how-can-i-use-the-return-format-unexpected-index-list-to-select-row-from-a-pandasdataset/70/3 "2021-05-24T23:37:42Z")

</div>

This was a great solution. Worked for me with the exception of the second to last line.

`df.ix` has been deprecated so you would just want to update that with `df.iloc[unexpected_indexes]`
