# String Index for DataFrames

**URL:** <https://discourse.julialang.org/t/string-index-for-dataframes/28390>\
**Category:** Data\
**Tags:** question\
**Created:** [September 4, 2019, 9:37pm UTC](https://discourse.julialang.org/t/string-index-for-dataframes/28390 "2019-09-04T21:37:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakyak](https://avatars.discourse-cdn.com/v4/letter/y/4bbf92/32.png) [@yakyak](https://discourse.julialang.org/u/yakyak)\
**Post date:** [September 4, 2019, 9:37pm UTC](https://discourse.julialang.org/t/string-index-for-dataframes/28390/1 "2019-09-04T21:37:36Z")

</div>

I am using the DataFrames package, and I would like to set a string column of it as the index. For example, let x =

```julia
│ Row │ name │ val│
│ │ String │ String │
├─────┼────────┼────────┤
│ 1 │ A │ 1│
│ 2 │ B │ 2│
│ 3 │ C │ 4│
│ 4 │ D │ 3│
│ 5 │ E │ 4│
│ 6 │ X │ 5│

```

Then, I want something like x[“A”, :val] to return 1. Currently, I have to do the following

```nohighlight
@where(x, :name .== "A")[1, :val]

```

which is bulky and unclear that the @where should only return one row. Is there anything like pandas `set_index` or an alternative? I’m having trouble understanding `setIndex!` in the DataFrames documentation, but it states that indices must be integers in any case.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [September 4, 2019, 10:27pm UTC](https://discourse.julialang.org/t/string-index-for-dataframes/28390/2 "2019-09-04T22:27:52Z")

</div>

Unfortunately currently DataFrames.jl does not allow indexing. `setindex!` is a function defined in Base and is used for setting values in a `DataFrame`. What you can do is:

```julia
filter(row->row.name == "A", df).val

```

or

```julia
df.val[df.name .== "A"]

```

or

```julia
df[df.name .== "A", :val]

```

or some variant of these.

There is an open PR [https://github.com/JuliaData/DataFrames.jl/pull/1908](https://github.com/JuliaData/DataFrames.jl/pull/1908) that after merging will allow you to do the following:

```julia
gd = groupby(df, :name) # this kind-of creates an index on df by grouping it
df[("A",)].val # get group defined by "A" as a SubDataFrame and fetch :val column from it

```
