Skip to content

Commit fdfa2f7

Browse files
authored
Mention DataFrameMacros.jl in the docs (#3195)
1 parent c1ff9cd commit fdfa2f7

File tree

4 files changed

+89
-3
lines changed

4 files changed

+89
-3
lines changed

docs/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[deps]
22
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
33
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
4+
Chain = "8be319e6-bccf-4806-a6f7-6fae938471bc"
5+
DataFrameMacros = "75880514-38bc-4a95-a458-c2aea5a3a702"
46
DataFramesMeta = "1313f7d8-7da2-5740-9ea0-a2ca25f37964"
57
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
68
Missings = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"

docs/src/index.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,15 @@ integrated they are with DataFrames.jl.
115115
A range of convenience functions for DataFrames.jl that augment `select` and
116116
`transform` to provide a user experience similar to that provided by
117117
[dplyr](https://dplyr.tidyverse.org/) in R.
118+
- [DataFrameMacros.jl](https://github.com/jkrumbiegel/DataFrameMacros.jl):
119+
Provides macro versions of the common DataFrames.jl functions similar to DataFramesMeta.jl,
120+
with convenient syntax for the manipulation of multiple columns at once.
118121
- [Query.jl](https://github.com/queryverse/Query.jl): Query.jl provides a single
119122
framework for data wrangling that works with a range of libraries, including
120123
DataFrames.jl, other tabular data libraries (more on those below), and even
121124
non-tabular data. Provides many convenience functions analogous to those in
122125
dplyr in R or [LINQ](https://en.wikipedia.org/wiki/Language_Integrated_Query).
123-
- You can find more on both of these packages in the
126+
- You can find more information on these packages in the
124127
[Data manipulation frameworks](@ref) section of this manual.
125128
- **And More!**
126129
- [Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl): A pure-Julia,

docs/src/man/querying_frameworks.md

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Data manipulation frameworks
22

3-
Two popular frameworks provide convenience methods to manipulate `DataFrame`s:
4-
DataFramesMeta.jl and Query.jl. They implement a functionality similar to
3+
Three frameworks provide convenience methods to manipulate `DataFrame`s:
4+
DataFramesMeta.jl, DataFrameMacros.jl and Query.jl. They implement a functionality similar to
55
[dplyr](https://dplyr.tidyverse.org/) or
66
[LINQ](https://en.wikipedia.org/wiki/Language_Integrated_Query).
77

@@ -117,6 +117,84 @@ julia> @chain df begin
117117
You can find more details about how this package can be used on the
118118
[DataFramesMeta.jl GitHub page](https://github.com/JuliaData/DataFramesMeta.jl).
119119

120+
## DataFrameMacros.jl
121+
122+
[DataFrameMacros.jl](https://github.com/jkrumbiegel/DataFrameMacros.jl) is
123+
an alternative to DataFramesMeta.jl with an additional focus on convenient
124+
solutions for the transformation of multiple columns at once.
125+
The instructions below are for version 0.3 of DataFrameMacros.jl.
126+
127+
First, install the DataFrameMacros.jl package:
128+
129+
```julia
130+
using Pkg
131+
Pkg.add("DataFrameMacros")
132+
```
133+
134+
In DataFrameMacros.jl, all but the `@combine` macro are row-wise by default.
135+
There is also a `@groupby` which allows creating grouping columns on the fly
136+
using the same syntax as `@transform`, for grouping by new columns
137+
without writing them out twice.
138+
139+
In the example below, you can also see some of DataFrameMacros.jl's multi-column
140+
features, where `mean` is applied to both age columns at once by selecting
141+
them with the `r"age"` regex. The new column names are then derived using the
142+
`"{}"` shortcut which splices the transformed column names into a string.
143+
144+
```jldoctest dataframemacros
145+
julia> using DataFrames, DataFrameMacros, Chain, Statistics
146+
147+
julia> df = DataFrame(name=["John", "Sally", "Roger"],
148+
age=[54.0, 34.0, 79.0],
149+
children=[0, 2, 4])
150+
3×3 DataFrame
151+
Row │ name age children
152+
│ String Float64 Int64
153+
─────┼───────────────────────────
154+
1 │ John 54.0 0
155+
2 │ Sally 34.0 2
156+
3 │ Roger 79.0 4
157+
158+
julia> @chain df begin
159+
@transform :age_months = :age * 12
160+
@groupby :has_child = :children > 0
161+
@combine "mean_{}" = mean({r"age"})
162+
end
163+
2×3 DataFrame
164+
Row │ has_child mean_age mean_age_months
165+
│ Bool Float64 Float64
166+
─────┼──────────────────────────────────────
167+
1 │ false 54.0 648.0
168+
2 │ true 56.5 678.0
169+
```
170+
171+
There's also the capability to reference a group of multiple columns as a single unit,
172+
for example to run aggregations over them, with the `{{ }}` syntax.
173+
In the following example, the first quarter is compared to the maximum of the other three:
174+
175+
```jldoctest dataframemacros
176+
julia> df = DataFrame(q1 = [12.0, 0.4, 42.7],
177+
q2 = [6.4, 2.3, 40.9],
178+
q3 = [9.5, 0.2, 13.6],
179+
q4 = [6.3, 5.4, 39.3])
180+
3×4 DataFrame
181+
Row │ q1 q2 q3 q4
182+
│ Float64 Float64 Float64 Float64
183+
─────┼────────────────────────────────────
184+
1 │ 12.0 6.4 9.5 6.3
185+
2 │ 0.4 2.3 0.2 5.4
186+
3 │ 42.7 40.9 13.6 39.3
187+
188+
julia> @transform df :q1_best = :q1 > maximum({{Not(:q1)}})
189+
3×5 DataFrame
190+
Row │ q1 q2 q3 q4 q1_best
191+
│ Float64 Float64 Float64 Float64 Bool
192+
─────┼─────────────────────────────────────────────
193+
1 │ 12.0 6.4 9.5 6.3 true
194+
2 │ 0.4 2.3 0.2 5.4 false
195+
3 │ 42.7 40.9 13.6 39.3 true
196+
```
197+
120198
## Query.jl
121199

122200
The [Query.jl](https://github.com/queryverse/Query.jl) package provides advanced

docs/src/man/working_with_dataframes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,9 @@ operations:
738738
- the [DataFramesMeta.jl](https://github.com/JuliaStats/DataFramesMeta.jl)
739739
package provides interfaces similar to LINQ and
740740
[dplyr](https://dplyr.tidyverse.org)
741+
- the [DataFrameMacros.jl](https://github.com/jkrumbiegel/DataFrameMacros.jl)
742+
package provides macros for most standard functions from DataFrames.jl,
743+
with convenient syntax for the manipulation of multiple columns at once.
741744

742745
See the [Data manipulation frameworks](@ref) section for more information.
743746

0 commit comments

Comments
 (0)