Skip to content

Commit

Permalink
Add insert! and pushfirst! (#3072)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkamins authored Jun 19, 2022
1 parent d645276 commit 0367281
Show file tree
Hide file tree
Showing 10 changed files with 2,250 additions and 1,192 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
* Add `resize!`, `keepat!`, `pop!`, `popfirst!`, and `popat!`,
make `deleteat!` signature more precise
([#3047](https://github.com/JuliaData/DataFrames.jl/pull/3047))
* Add `pushfirst!` and `insert!`
([#3072](https://github.com/JuliaData/DataFrames.jl/pull/3072))
* New `threads` argument allows disabling multithreading in
`combine`, `select`, `select!`, `transform`, `transform!`, `subset` and `subset!`
([#3030](https://github.com/JuliaData/DataFrames.jl/pull/3030))
Expand Down
2 changes: 2 additions & 0 deletions docs/src/lib/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ combine
fillcombinations
flatten
hcat
insert!
insertcols
insertcols!
invpermute!
Expand All @@ -86,6 +87,7 @@ mapcols!
permute!
prepend!
push!
pushfirst!
reduce
repeat
repeat!
Expand Down
9 changes: 8 additions & 1 deletion docs/src/man/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ julia> df = DataFrame(A=Int[], B=String[])
0×2 DataFrame
```

Rows can then be added as tuples or vectors, where the order of elements matches that of columns:
Rows can then be added as tuples or vectors, where the order of elements matches that of columns.
To add new rows at the end of a data frame use [`push!`](@ref):

```jldoctest dataframe
julia> push!(df, (1, "M"))
Expand Down Expand Up @@ -261,6 +262,12 @@ Note that constructing a `DataFrame` row by row is significantly less performant
constructing it all at once, or column by column. For many use-cases this will not matter,
but for very large `DataFrame`s this may be a consideration.

If you want to add rows at the beginning of a data frame use [`pushfirst!`](@ref)
and to insert a row in an arbitrary location use [`insert!`]((@ref)).

You can also add whole tables to a data frame using the [`append!`](@ref)
and [`prepend!`](@ref) functions.

### Constructing from another table type

DataFrames supports the [Tables.jl](https://github.com/JuliaData/Tables.jl) interface for
Expand Down
2 changes: 2 additions & 0 deletions src/DataFrames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ include("abstractdataframe/abstractdataframe.jl")
include("dataframe/dataframe.jl")
include("subdataframe/subdataframe.jl")
include("dataframerow/dataframerow.jl")
include("dataframe/insertion.jl")

include("groupeddataframe/groupeddataframe.jl")
include("groupeddataframe/utils.jl")

Expand Down
Loading

0 comments on commit 0367281

Please sign in to comment.