# How to run an expectation only if the column exists

**URL:** <https://discourse.greatexpectations.io/t/how-to-run-an-expectation-only-if-the-column-exists/573>\
**Category:** Archive\
**Tags:** help-wanted\
**Created:** [December 22, 2020, 9:21am UTC](https://discourse.greatexpectations.io/t/how-to-run-an-expectation-only-if-the-column-exists/573 "2020-12-22T09:21:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leononame](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.greatexpectations.io/leononame/32/105_2.png) [@leononame](https://discourse.greatexpectations.io/u/leononame)\
**Post date:** [December 22, 2020, 9:21am UTC](https://discourse.greatexpectations.io/t/how-to-run-an-expectation-only-if-the-column-exists/573/1 "2020-12-22T09:21:34Z")

</div>

Hi Team, Hi Community,

I’ve been trying to get an expectation to work but I think I need help. I want to use `expect_column_values_to_be_between`, but only actually run the expectation if the column exists. If the column does not exist, I do not care about validating it. My data source is a CSV with pandas.

When just coding the expectation, I get KeyError on files where the given column does not exist and passing in `catch_exceptions` catches the exceptions but still fails the suite and marks the expectation as error. I want it to succeed if the column doesn’t exist and validate if the column does exist. I’ve been trying to get `row_condition` to work for me, but the pandas query engine doesn’t seem to support querying whether a column exists as it is intended for expression syntax in columns.

---

<div class="post-metadata">

**Author:** ![eugene.mandel](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.greatexpectations.io/eugene.mandel/32/22_2.png) [@eugene.mandel](https://discourse.greatexpectations.io/u/eugene.mandel)\
**Post date:** [January 11, 2021, 3:57am UTC](https://discourse.greatexpectations.io/t/how-to-run-an-expectation-only-if-the-column-exists/573/2 "2021-01-11T03:57:01Z")

</div>

Currently Expectations do not support this conditionality (“if column exists”). This might be a good enhancement. For now, one way to solve it is to create two Expectation Suites - one with this expectations and one without. Then you can decide which one to apply to a particular batch of data, depending on the presence of the column.

---

<div class="post-metadata">

**Author:** ![dansasbu](https://avatars.discourse-cdn.com/v4/letter/d/a88e4f/32.png) [@dansasbu](https://discourse.greatexpectations.io/u/dansasbu)\
**Post date:** [September 1, 2021, 6:08pm UTC](https://discourse.greatexpectations.io/t/how-to-run-an-expectation-only-if-the-column-exists/573/3 "2021-09-01T18:08:56Z")

</div>

Hi, any idea in how can I proceed if I need this use case? I mean, for me is unfeasible to build several suites because I don’t know when a column won’t be present. I need to validate a column only if it exists on the data set.

---

<div class="post-metadata">

**Author:** ![Ntlzyjstdntcare](https://avatars.discourse-cdn.com/v4/letter/n/e9a140/32.png) [@Ntlzyjstdntcare](https://discourse.greatexpectations.io/u/Ntlzyjstdntcare)\
**Post date:** [September 30, 2021, 12:13pm UTC](https://discourse.greatexpectations.io/t/how-to-run-an-expectation-only-if-the-column-exists/573/4 "2021-09-30T12:13:05Z")

</div>

I’m also very keen to see this feature. Having one uber-suite would be much more manageable for us compared to having lots and lots of suites.
