# Random access to rows of a table

**URL:** <https://discourse.julialang.org/t/random-access-to-rows-of-a-table/77386>\
**Category:** Machine Learning\
**Created:** [March 4, 2022, 1:18am UTC](https://discourse.julialang.org/t/random-access-to-rows-of-a-table/77386 "2022-03-04T01:18:49Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [March 10, 2022, 9:20am UTC](https://discourse.julialang.org/t/random-access-to-rows-of-a-table/77386/15 "2022-03-10T09:20:37Z")

</div>

> [@ablaom](#):
>
> I want the best performance the particular table I am using has to offer, assuming the provider of the table type has implemented the new interface, and otherwise, it should just work.
> 
> I don’t understand “So what the API should look like depends on the use case.” Could you elaborate?

For example, for a `DataFrame`, if you just want to split the data in a few subsets, this can be done efficiently by indexing the `DataFrame` object with a vector of indices; so DataFrames could implement that generic API by simply calling its `getindex` method. Even for other table types which are not as suited to random access as `DataFrame` (like SQL tables), indexing with a vector could probably be implemented with an acceptable performance if you only take a few subsets.

On the contrary, if what you want is index single rows repeatedly in a performance-critical part of the code, then maybe you’d better work on a named tuple of columns (or a matrix) than on a `DataFrame`; the API would have to include e.g. a `fastindexingtable` function that you would call to get that named tuple of columns before performing repeated indexing. Likewise, for types such as SQL tables, the only solution would be to copy everything in memory first.

From your description, it seems you care about the first case? Indeed it seems the simplest to support.

---

_[View the full topic](https://discourse.julialang.org/t/random-access-to-rows-of-a-table/77386)._
