# Create a GroupedDataFrame by the relations of rows rather than the values of the rows in a column, e.g \`groupby\` consecutive dates?

**URL:** https://discourse.julialang.org/t/create-a-groupeddataframe-by-the-relations-of-rows-rather-than-the-values-of-the-rows-in-a-column-e-g-groupby-consecutive-dates/96493
**Category:** New to Julia
**Tags:** question, dataframes, grouped-data
**Created:** [March 23, 2023, 6:27am UTC](https://discourse.julialang.org/t/create-a-groupeddataframe-by-the-relations-of-rows-rather-than-the-values-of-the-rows-in-a-column-e-g-groupby-consecutive-dates/96493 "2023-03-23T06:27:17Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![phantom](https://avatars.discourse-cdn.com/v4/letter/p/e0b2c6/32.png) [@phantom](https://discourse.julialang.org/u/phantom)
#### Post date: [March 24, 2023, 8:13pm UTC](https://discourse.julialang.org/t/create-a-groupeddataframe-by-the-relations-of-rows-rather-than-the-values-of-the-rows-in-a-column-e-g-groupby-consecutive-dates/96493/5 "2023-03-24T20:13:30Z")

</div>

Thanks! Sorry so is the following a correct understanding of when type declarations improve performance?

1. If a function takes a` column` of a DataFrame as an argument then type declarations do not improve performance.

2. If a function takes an _entire_ `DataFrame` as an argument then type declarations on each column will improve performance.

The [docs](https://docs.julialang.org/en/v1/manual/functions/#Argument-type-declarations) on argument type declarations note that they generally do not enhance performance. But as you pointed out in a previous [post](https://discourse.julialang.org/t/is-there-an-equivalent-of-eachindex-for-dataframes/88945/2) about efficiency in iterating over columns of a DataFrame that:

> [@Is there an equivalent of eachindex() for DataFrames?](https://discourse.julialang.org/t/is-there-an-equivalent-of-eachindex-for-dataframes/88945/6):
>
> The point is that in order to be efficient you must pass a column to a separate function. Then inside this function all will be fast.
> 
> The reason is that `DataFrame` object is not type stable, so for example even:
> 
> ```julia
> for col in eachcol(df)
> for v in col
> ... your code
> end
> end
> 
> ```
> 
> will be slow, because Julia does not know the element type of `col` at compilation time.

and also that

> [@Is there an equivalent of eachindex() for DataFrames?](https://discourse.julialang.org/t/is-there-an-equivalent-of-eachindex-for-dataframes/88945/8):
>
> If all columns have the same type then what is enough is:
> 
> ```julia
> for col in eachcol(df)
> for v in col::Vector{String} # assuming this is the type of column
> ... your code
> end
> end
> 
> ```
> 
> of course converting to a `Matrix` or to `Tables.columntable` also will work in this case.

My background is so minimal that I wasn’t sure whether type declarations here improved performance because the loop was entirely outside of a function or because the entire DataFrame was being passed as an argument into a function?

Assuming the latter, why does a function barrier work for a column of a DataFrame but not the entire DataFrame? Wouldn’t the type stability issue affect both the `DataFrame` object and the `DataFrame col`?

---

_[View the full topic](https://discourse.julialang.org/t/create-a-groupeddataframe-by-the-relations-of-rows-rather-than-the-values-of-the-rows-in-a-column-e-g-groupby-consecutive-dates/96493)._
