# How to filter a df with startswith() in a field?

**URL:** <https://discourse.julialang.org/t/how-to-filter-a-df-with-startswith-in-a-field/4837>\
**Category:** Data\
**Tags:** question, data\
**Created:** [July 13, 2017, 2:02pm UTC](https://discourse.julialang.org/t/how-to-filter-a-df-with-startswith-in-a-field/4837 "2017-07-13T14:02:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [July 13, 2017, 2:02pm UTC](https://discourse.julialang.org/t/how-to-filter-a-df-with-startswith-in-a-field/4837/1 "2017-07-13T14:02:41Z")

</div>

Nor these two approach works:

```julia
df = DataFrame(field1 = ["abc", "abb", "acc"])
pattern = "ab"
ps = sizeof(pattern)
filteredDf = myData[df[:field1][1:ps] .== pattern), :] 
filteredDf = myData[startswith(df[:field1],pattern), :]

```

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [July 13, 2017, 2:06pm UTC](https://discourse.julialang.org/t/how-to-filter-a-df-with-startswith-in-a-field/4837/2 "2017-07-13T14:06:30Z")

</div>

my error… this works (Julia 0.6):

`filteredDf = df[startswith.(df[:field1],pattern),:]`
