# Filtering a DataFrame column using Regex

**URL:** <https://discourse.julialang.org/t/filtering-a-dataframe-column-using-regex/40753>\
**Category:** Data\
**Tags:** dataframes\
**Created:** [June 4, 2020, 6:33pm UTC](https://discourse.julialang.org/t/filtering-a-dataframe-column-using-regex/40753 "2020-06-04T18:33:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alejandromerchan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alejandromerchan/32/10500_2.png) [@alejandromerchan](https://discourse.julialang.org/u/alejandromerchan)\
**Post date:** [June 4, 2020, 6:33pm UTC](https://discourse.julialang.org/t/filtering-a-dataframe-column-using-regex/40753/1 "2020-06-04T18:33:31Z")

</div>

I have a DataFrame that has this general structure

```julia
using DataFrames

df = DataFrame(Sites = ["N-1", "N-1", "A", "B", "N-2"], Other = [randn(5)])

```

How can I filter out the rows that are named “N-” on the column `:Sites`? I know I can use Regex and `Not` but my naive approach didn’t work.

```julia
filter(:Sites => x -> x == Not(r"N-"), df)

```

How can I perform this operation?

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [June 4, 2020, 6:41pm UTC](https://discourse.julialang.org/t/filtering-a-dataframe-column-using-regex/40753/2 "2020-06-04T18:41:17Z")

</div>

`Not` doesn’t work like that. The way you are working with `Not` is similar to a workflow one might use with selecting columns, not rows.

You want `occursin`

```julia
julia> filter(:Sites => t -> occursin(r"N", t) == false, df)

```

---

<div class="post-metadata">

**Author:** ![alejandromerchan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alejandromerchan/32/10500_2.png) [@alejandromerchan](https://discourse.julialang.org/u/alejandromerchan)\
**Post date:** [June 4, 2020, 6:43pm UTC](https://discourse.julialang.org/t/filtering-a-dataframe-column-using-regex/40753/3 "2020-06-04T18:43:18Z")

</div>

Ok, good to know.

Thanks
