Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 100 additions & 93 deletions docs/src/man/basics.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/src/man/comparisons.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Name: x, dtype: int64

For DataFrames.jl, it looks like this:

```julia
```julia-repl
julia> combine(groupby(df, :grp), :x => mean)
2×2 DataFrame
Row │ grp x_mean
Expand Down
27 changes: 7 additions & 20 deletions docs/src/man/customizing_output.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ julia> df = DataFrame(
c = ["short", "a very very very very very long string", "ok"]
);

julia> # This is the default output.

julia> df
julia> df # This is the default output.
3×3 DataFrame
Row │ a b c
│ Int64 Float64 String
Expand All @@ -62,9 +60,7 @@ julia> show(df; truncate = 0)
2 │ 2 -1.2 a very very very very very long string
3 │ 3 42.0 ok

julia> # Hide row numbers.

julia> show(df; show_row_number = false)
julia> show(df; show_row_number = false) # Hide row numbers.
3×3 DataFrame
a b c
Int64 Float64 String
Expand All @@ -73,9 +69,7 @@ julia> show(df; show_row_number = false)
2 -1.2 a very very very very very long …
3 42.0 ok

julia> # Hide the column element types in text output.

julia> show(df; eltypes = false)
julia> show(df; eltypes = false) # Hide the column element types in text output.
3×3 DataFrame
Row │ a b c
─────┼─────────────────────────────────────────────
Expand Down Expand Up @@ -119,9 +113,7 @@ julia> df = DataFrame(
E = [ 0.26, -1.67, 2.22, -0.75, 1.05, -0.48, -2.93]
);

julia> # This is the default output.

julia> df
julia> df # This is the default output.
7×5 DataFrame
Row │ A B C D E
│ Float64 Float64 Float64 Float64 Float64
Expand Down Expand Up @@ -157,15 +149,10 @@ julia> show(df; formatters = [parentheses_fmt])
The color of the cells can be changed using highlighters. The following example shows how to
highlight negative values in red in HTML output (e.g. in Jupyter).

```julia
```julia-repl
julia> hl = HtmlHighlighter((data, i, j) -> data[i, j] < 0, ["color" => "red"]);

julia> show(
stdout,
MIME("text/html"),
df;
highlighters = [hl]
)
julia> show(stdout, MIME("text/html"), df; highlighters = [hl])
```

You can also add summary rows at the bottom of a table using PrettyTables.jl keywords. Pass
Expand Down Expand Up @@ -211,4 +198,4 @@ julia> show(
```

For more customization options, check the
[PrettyTables.jl documentation](https://ronisbr.github.io/PrettyTables.jl/stable/).
[PrettyTables.jl documentation](https://ronisbr.github.io/PrettyTables.jl/stable/).
2 changes: 1 addition & 1 deletion docs/src/man/joins.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ Note that in this case the order and number of rows in the left table is not
changed. Therefore, in particular, it is not allowed to have duplicate keys
in the right table:

```
```julia-repl
julia> leftjoin!(main, DataFrame(id=[2, 2], info_bad=["a", "b"]), on=:id)
ERROR: ArgumentError: duplicate rows found in right table
```
66 changes: 46 additions & 20 deletions docs/src/man/split_apply_combine.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ julia> combine(iris_gdf, :PetalLength => (x -> [extrema(x)]) => [:min, :max])
```

To get row number for each observation within each group use the `eachindex` function:
```
```jldoctest sac
julia> combine(iris_gdf, eachindex)
150×2 DataFrame
Row │ Species eachindex
Expand All @@ -332,48 +332,74 @@ julia> combine(iris_gdf, eachindex)
1 │ Iris-setosa 1
2 │ Iris-setosa 2
3 │ Iris-setosa 3
4 │ Iris-setosa 4
5 │ Iris-setosa 5
6 │ Iris-setosa 6
7 │ Iris-setosa 7
8 │ Iris-setosa 8
⋮ │ ⋮ ⋮
144 │ Iris-virginica 44
145 │ Iris-virginica 45
146 │ Iris-virginica 46
147 │ Iris-virginica 47
148 │ Iris-virginica 48
149 │ Iris-virginica 49
150 │ Iris-virginica 50
144 rows omitted
135 rows omitted
```

Contrary to `combine`, the `select` and `transform` functions always return
a data frame with the same number and order of rows as the source.
In the example below
the return values in columns `:SepalLength_SepalWidth_cor` and `:nrow` are
broadcasted to match the number of elements in each group:
```

```jldoctest sac
julia> select(iris_gdf, 1:2 => cor)
150×2 DataFrame
Row │ Species SepalLength_SepalWidth_cor
String Float64
String15 Float64
─────┼────────────────────────────────────────────
1 │ Iris-setosa 0.74678
2 │ Iris-setosa 0.74678
3 │ Iris-setosa 0.74678
4 │ Iris-setosa 0.74678
5 │ Iris-setosa 0.74678
6 │ Iris-setosa 0.74678
7 │ Iris-setosa 0.74678
8 │ Iris-setosa 0.74678
⋮ │ ⋮ ⋮
144 │ Iris-virginica 0.457228
145 │ Iris-virginica 0.457228
146 │ Iris-virginica 0.457228
147 │ Iris-virginica 0.457228
148 │ Iris-virginica 0.457228
149 │ Iris-virginica 0.457228
150 │ Iris-virginica 0.457228
143 rows omitted
135 rows omitted

julia> transform(iris_gdf, :Species => x -> chop.(x, head=5, tail=0))
150×6 DataFrame
Row │ SepalLength SepalWidth PetalLength PetalWidth Species Species_function
│ Float64 Float64 Float64 Float64 String SubString…
─────┼────────────────────────────────────────────────────────────────────────────────────
1 │ 5.1 3.5 1.4 0.2 Iris-setosa setosa
2 │ 4.9 3.0 1.4 0.2 Iris-setosa setosa
3 │ 4.7 3.2 1.3 0.2 Iris-setosa setosa
4 │ 4.6 3.1 1.5 0.2 Iris-setosa setosa
⋮ │ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮
148 │ 6.5 3.0 5.2 2.0 Iris-virginica virginica
149 │ 6.2 3.4 5.4 2.3 Iris-virginica virginica
150 │ 5.9 3.0 5.1 1.8 Iris-virginica virginica
143 rows omitted
Row │ SepalLength SepalWidth PetalLength PetalWidth Species Speci ⋯
│ Float64 Float64 Float64 Float64 String15 Strin ⋯
─────┼──────────────────────────────────────────────────────────────────────────
1 │ 5.1 3.5 1.4 0.2 Iris-setosa setos ⋯
2 │ 4.9 3.0 1.4 0.2 Iris-setosa setos
3 │ 4.7 3.2 1.3 0.2 Iris-setosa setos
4 │ 4.6 3.1 1.5 0.2 Iris-setosa setos
5 │ 5.0 3.6 1.4 0.2 Iris-setosa setos ⋯
6 │ 5.4 3.9 1.7 0.4 Iris-setosa setos
7 │ 4.6 3.4 1.4 0.3 Iris-setosa setos
8 │ 5.0 3.4 1.5 0.2 Iris-setosa setos
⋮ │ ⋮ ⋮ ⋮ ⋮ ⋮ ⋱
144 │ 6.8 3.2 5.9 2.3 Iris-virginica virgi ⋯
145 │ 6.7 3.3 5.7 2.5 Iris-virginica virgi
146 │ 6.7 3.0 5.2 2.3 Iris-virginica virgi
147 │ 6.3 2.5 5.0 1.9 Iris-virginica virgi
148 │ 6.5 3.0 5.2 2.0 Iris-virginica virgi ⋯
149 │ 6.2 3.4 5.4 2.3 Iris-virginica virgi
150 │ 5.9 3.0 5.1 1.8 Iris-virginica virgi
1 column and 135 rows omitted
```

All functions also support the `do` block form. However, as noted above,
Expand Down Expand Up @@ -730,7 +756,7 @@ syntax in `combine`, `select` or `transform` will usually be faster for large
`GroupedDataFrame` objects than iterating them, with the difference that they
produce a data frame. An operation corresponding to the example above is:

```
```julia-repl
julia> combine(iris_gdf, nrow)
3×2 DataFrame
Row │ Species nrow
Expand Down Expand Up @@ -1311,7 +1337,7 @@ julia> keys(groupby(df, :volume))

If you want to have them sorted in ascending order pass `sort=true`:

```
```julia-repl
julia> keys(groupby(df, :volume, sort=true))
7-element DataFrames.GroupKeys{GroupedDataFrame{DataFrame}}:
GroupKey: (volume = 1,)
Expand All @@ -1328,7 +1354,7 @@ by or pass a named tuple as `sort` keyword argument containing one or more of
`alg`, `lt`, `by`, `rev`, and `order` fields that will be treated just like in
[`sortperm`](@ref):

```
```julia-repl
julia> keys(groupby(df, [:customer_id, order(:volume, rev=true)]))
6-element DataFrames.GroupKeys{GroupedDataFrame{DataFrame}}:
GroupKey: (customer_id = "a", volume = 2)
Expand Down
23 changes: 11 additions & 12 deletions docs/src/man/working_with_dataframes.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ julia> df[:, :x1]

By default `select` copies columns of a passed source data frame.
In order to avoid copying, pass `copycols=false`:
```
```jldoctest dataframe
julia> df2 = select(df, :x1)
2×1 DataFrame
Row │ x1
Expand Down Expand Up @@ -668,7 +668,7 @@ julia> transform(df, All() => +)
Using the `ByRow` wrapper, we can easily compute for each row the name of column
with the highest score:

```
```julia-repl
julia> using Random

julia> Random.seed!(1);
Expand Down Expand Up @@ -709,8 +709,8 @@ julia> transform(df, AsTable(:) => ByRow(argmax) => :prediction)
In the most complex example below we compute row-wise sum, number of
elements, and mean, while ignoring missing values.

```
julia> using Statistics
```jldoctest
julia> using DataFrames, Statistics

julia> df = DataFrame(x=[1, 2, missing], y=[1, missing, missing])
3×2 DataFrame
Expand Down Expand Up @@ -844,7 +844,7 @@ want to focus on the most common usage patterns.
A `DataFrame` can store values of any type as its columns, for example
below we show how one can store a `Tuple`:

```
```jldoctest dataframe
julia> df2 = combine(df, All() .=> extrema)
1×2 DataFrame
Row │ A_extrema B_extrema
Expand All @@ -858,7 +858,7 @@ minima and maxima. This can be achieved by passing multiple columns for the outp
Here is an example of how this can be done by writing the column names by-hand for a single
input column:

```
```jldoctest dataframe
julia> combine(df2, "A_extrema" => identity => ["A_min", "A_max"])
1×2 DataFrame
Row │ A_min A_max
Expand All @@ -869,7 +869,7 @@ julia> combine(df2, "A_extrema" => identity => ["A_min", "A_max"])

You can extend it to handling all columns in `df2` using broadcasting:

```
```jldoctest dataframe
julia> combine(df2, All() .=> identity .=> [["A_min", "A_max"], ["B_min", "B_max"]])
1×4 DataFrame
Row │ A_min A_max B_min B_max
Expand All @@ -882,7 +882,7 @@ This approach works, but can be improved. Instead of writing all the column name
manually we can instead use a function as a way to specify target column names
based on source column names:

```
```jldoctest dataframe
julia> combine(df2, All() .=> identity .=> c -> first(c) .* ["_min", "_max"])
1×4 DataFrame
Row │ A_min A_max B_min B_max
Expand All @@ -898,7 +898,7 @@ treated as a transformation and not as a rule for target column names generation
You might want to perform the transformation of the source data frame into the result
we have just shown in one step. This can be achieved with the following expression:

```
```jldoctest dataframe
julia> combine(df, All() .=> Ref∘extrema .=> c -> c .* ["_min", "_max"])
1×4 DataFrame
Row │ A_min A_max B_min B_max
Expand All @@ -912,10 +912,9 @@ Without `Ref`, `combine` iterates the contents of the value returned by the oper
which in our case is a tuple of numbers, and tries to expand it assuming that each produced value represents one row,
so one gets an error:

```
```jldoctest dataframe
julia> combine(df, All() .=> extrema .=> [c -> c .* ["_min", "_max"]])
ERROR: ArgumentError: 'Tuple{Int64, Int64}' iterates 'Int64' values,
which doesn't satisfy the Tables.jl `AbstractRow` interface
ERROR: ArgumentError: 'Tuple{Int64, Int64}' iterates 'Int64' values, which doesn't satisfy the Tables.jl `AbstractRow` interface
```

Note that we used `Ref` as it is a container that is typically used in DataFrames.jl when one
Expand Down
4 changes: 2 additions & 2 deletions src/abstractdataframe/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ implicit row ID column contained in every `AbstractDataFrame`.
# Arguments
- `df::AbstractDataFrame`: The data frame whose columns will be printed.
- `io::IO`: The `IO` to which `df` is to be printed
- `rowindices1::AbstractVector{Int}: A set of indices of the first
- `rowindices1::AbstractVector{Int}`: A set of indices of the first
chunk of the AbstractDataFrame that would be rendered to IO.
- `rowindices2::AbstractVector{Int}: A set of indices of the second
- `rowindices2::AbstractVector{Int}`: A set of indices of the second
chunk of the AbstractDataFrame that would be rendered to IO. Can
be empty if the AbstractDataFrame would be printed without any
ellipses.
Expand Down
2 changes: 1 addition & 1 deletion src/abstractdataframe/selectionfast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ scenarios even standard aggregation functions should not be considered to
provide reliable output, and users are recommended to switch to higher precision
calculations. An example of a case when standard `sum` is affected by the
situation discussed is:
```
```julia-repl
julia> sum(Any[typemax(Int), typemax(Int), 1.0])
-1.0

Expand Down
6 changes: 0 additions & 6 deletions src/other/metadata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ See also: [`metadatakeys`](@ref), [`metadata!`](@ref),
[`deletecolmetadata!`](@ref), [`emptycolmetadata!`](@ref).

$TABLEMETA_EXAMPLE
```
"""
function metadata(df::DataFrame, key::AbstractString,
default=MetadataMissingDefault(); style::Bool=false)
Expand Down Expand Up @@ -186,7 +185,6 @@ See also: [`metadata`](@ref), [`metadatakeys`](@ref),
[`deletecolmetadata!`](@ref), [`emptycolmetadata!`](@ref).

$TABLEMETA_EXAMPLE
```
"""
function metadata!(df::DataFrame, key::AbstractString, value::Any;
style::Symbol=:default)
Expand Down Expand Up @@ -245,7 +243,6 @@ See also: [`metadata`](@ref), [`metadatakeys`](@ref),
[`deletecolmetadata!`](@ref), [`emptycolmetadata!`](@ref).

$TABLEMETA_EXAMPLE
```
"""
function deletemetadata!(df::DataFrame, key::AbstractString)
meta = getfield(df, :metadata)
Expand Down Expand Up @@ -355,7 +352,6 @@ See also: [`metadata`](@ref), [`metadatakeys`](@ref),
[`deletecolmetadata!`](@ref), [`emptycolmetadata!`](@ref).

$COLMETADATA_EXAMPLE
```
"""
function colmetadata(df::DataFrame, col::ColumnIndex, key::AbstractString,
default=MetadataMissingDefault(); style::Bool=false)
Expand Down Expand Up @@ -421,7 +417,6 @@ See also: [`metadata`](@ref), [`metadatakeys`](@ref),
[`deletecolmetadata!`](@ref), [`emptycolmetadata!`](@ref).

$COLMETADATA_EXAMPLE
```
"""
function colmetadatakeys(df::DataFrame, col::ColumnIndex)
idx = index(df)[col] # check if column exists and get its integer index
Expand Down Expand Up @@ -483,7 +478,6 @@ See also: [`metadata`](@ref), [`metadatakeys`](@ref),
[`deletecolmetadata!`](@ref), [`emptycolmetadata!`](@ref).

$COLMETADATA_EXAMPLE
```
"""
function colmetadata!(df::DataFrame, col::ColumnIndex, key::AbstractString, value::Any;
style::Symbol=:default)
Expand Down
Loading