Skip to content

Commit 84cd36b

Browse files
authored
Small formatting tweaks to #3360 after reviewing online (#3483)
1 parent dc59622 commit 84cd36b

File tree

1 file changed

+47
-37
lines changed

1 file changed

+47
-37
lines changed

docs/src/man/basics.md

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,32 +1635,36 @@ The `operation` argument defines the
16351635
operation to be applied to the source `dataframe`,
16361636
and it can take any of the following common forms explained below:
16371637

1638-
`source_column_selector`
1639-
: selects source column(s) without manipulating or renaming them
1638+
* `source_column_selector`
16401639

1641-
Examples: `:a`, `[:a, :b]`, `All()`, `Not(:a)`
1640+
selects source column(s) without manipulating or renaming them
16421641

1643-
`source_column_selector => operation_function`
1644-
: passes source column(s) as arguments to a function
1645-
and automatically names the resulting column(s)
1642+
Examples: `:a`, `[:a, :b]`, `All()`, `Not(:a)`
16461643

1647-
Examples: `:a => sum`, `[:a, :b] => +`, `:a => ByRow(==(3))`
1644+
* `source_column_selector => operation_function`
16481645

1649-
`source_column_selector => operation_function => new_column_names`
1650-
: passes source column(s) as arguments to a function
1651-
and names the resulting column(s) `new_column_names`
1646+
passes source column(s) as arguments to a function
1647+
and automatically names the resulting column(s)
16521648

1653-
Examples: `:a => sum => :sum_of_a`, `[:a, :b] => (+) => :a_plus_b`
1649+
Examples: `:a => sum`, `[:a, :b] => +`, `:a => ByRow(==(3))`
16541650

1655-
*(Not available for `subset` or `subset!`)*
1651+
* `source_column_selector => operation_function => new_column_names`
16561652

1657-
`source_column_selector => new_column_names`
1658-
: renames a source column,
1659-
or splits a column containing collection elements into multiple new columns
1653+
passes source column(s) as arguments to a function
1654+
and names the resulting column(s) `new_column_names`
16601655

1661-
Examples: `:a => :new_a`, `:a_b => [:a, :b]`, `:nt => AsTable`
1656+
Examples: `:a => sum => :sum_of_a`, `[:a, :b] => (+) => :a_plus_b`
16621657

1663-
(*Not available for `subset` or `subset!`*)
1658+
*(Not available for `subset` or `subset!`)*
1659+
1660+
* `source_column_selector => new_column_names`
1661+
1662+
renames a source column,
1663+
or splits a column containing collection elements into multiple new columns
1664+
1665+
Examples: `:a => :new_a`, `:a_b => [:a, :b]`, `:nt => AsTable`
1666+
1667+
(*Not available for `subset` or `subset!`*)
16641668

16651669
The `=>` operator constructs a
16661670
[Pair](https://docs.julialang.org/en/v1/base/collections/#Core.Pair),
@@ -1747,7 +1751,7 @@ julia> subset(df, :minor)
17471751
```
17481752

17491753
`source_column_selector` may instead be a collection of columns such as a vector,
1750-
a [regular expression](https://docs.julialang.org/en/v1/manual/strings/#Regular-Expressions),
1754+
a [regular expression](https://docs.julialang.org/en/v1/manual/strings/#man-regex-literals),
17511755
a `Not`, `Between`, `All`, or `Cols` expression,
17521756
or a `:`.
17531757
See the [Indexing](@ref) API for the full list of possible values with references.
@@ -2279,7 +2283,8 @@ julia> transform(df, :b => (x -> x .+ 10) => :a) # replace column :a
22792283
418 8
22802284
```
22812285

2282-
Actually, `renamecols=false` just prevents the function name from being appended to the final column name such that the operation is *usually* returned to the same column.
2286+
Actually, `renamecols=false` just prevents the function name from being appended
2287+
to the final column name such that the operation is *usually* returned to the same column.
22832288

22842289
```julia
22852290
julia> transform(df, [:a, :b] => +) # new column name is all source columns and function name
@@ -2939,13 +2944,18 @@ julia> select(
29392944

29402945
!!! note "Notes"
29412946

2942-
* `Not("Time")` or `2:4` would have been equally good choices for `source_column_selector` in the above operations.
2943-
* Don't forget `ByRow` if your function is to be applied to elements rather than entire column vectors.
2944-
Without `ByRow`, the manipulations above would have thrown
2945-
`ERROR: MethodError: no method matching +(::Vector{Int64}, ::Int64)`.
2947+
* `Not("Time")` or `2:4` would have been equally good choices
2948+
for `source_column_selector` in the above operations.
2949+
2950+
* Don't forget `ByRow` if your function is to be applied to elements
2951+
rather than entire column vectors.
2952+
Without `ByRow`, the manipulations above would have thrown
2953+
`ERROR: MethodError: no method matching +(::Vector{Int64}, ::Int64)`.
2954+
29462955
* Regular expression (`r""`) and `:` `source_column_selectors`
2947-
must be wrapped in `Cols` to be properly broadcasted
2948-
because otherwise the broadcasting occurs before the expression is expanded into a vector of matches.
2956+
must be wrapped in `Cols` to be properly broadcasted
2957+
because otherwise the broadcasting occurs before the expression
2958+
is expanded into a vector of matches.
29492959

29502960
You could also broadcast different columns to different functions
29512961
by supplying a vector of functions.
@@ -3095,7 +3105,8 @@ julia> df # see that the previous expression updated the data frame `df`
30953105
33 6 9
30963106
```
30973107

3098-
Recall that the return type from a data frame manipulation function call is always a data frame.
3108+
Recall that the return type from a data frame manipulation function call
3109+
is always a data frame.
30993110
The return type of a data frame column accessed with dot syntax is a `Vector`.
31003111
Thus the expression `df.x + df.y` gets the column data as vectors
31013112
and returns the result of the vector addition.
@@ -3210,7 +3221,6 @@ julia> my_very_long_data_frame_name = DataFrame(
32103221

32113222
julia> c1 = "My First Column"; c2 = "My Second Column"; c3 = "My Third Column"; # define column names
32123223
```
3213-
32143224
**Manipulation:**
32153225

32163226
```julia
@@ -3267,16 +3277,10 @@ julia> df.Not(:x) # will not work; requires a literal column name
32673277
ERROR: ArgumentError: column name :Not not found in the data frame
32683278
```
32693279

3270-
**Indexing:**
3280+
**Manipulation:**
32713281

32723282
```julia
3273-
julia> df[:, :y_z_max] = maximum.(eachrow(df[:, Not(:x)])) # find maximum value across all rows except for column `x`
3274-
3-element Vector{Int64}:
3275-
7
3276-
8
3277-
9
3278-
3279-
julia> df # see that the previous expression updated the data frame `df`
3283+
julia> transform!(df, Not(:x) => ByRow(max)) # find maximum value across all rows except for column `x`
32803284
3×4 DataFrame
32813285
Row │ x y z y_z_max
32823286
│ Int64 Int64 Int64 Int64
@@ -3286,10 +3290,16 @@ julia> df # see that the previous expression updated the data frame `df`
32863290
33 6 9 9
32873291
```
32883292

3289-
**Manipulation:**
3293+
**Indexing:**
32903294

32913295
```julia
3292-
julia> transform!(df, Not(:x) => ByRow(max)) # find maximum value across all rows except for column `x`
3296+
julia> df[:, :y_z_max] = maximum.(eachrow(df[:, Not(:x)])) # find maximum value across all rows except for column `x`
3297+
3-element Vector{Int64}:
3298+
7
3299+
8
3300+
9
3301+
3302+
julia> df # see that the previous expression updated the data frame `df`
32933303
3×4 DataFrame
32943304
Row │ x y z y_z_max
32953305
│ Int64 Int64 Int64 Int64

0 commit comments

Comments
 (0)