@@ -695,7 +695,8 @@ Base.transpose(::AbstractDataFrame, args...; kwargs...) =
695695 throw (ArgumentError (" `transpose` not defined for `AbstractDataFrame`s. Try `permutedims` instead" ))
696696
697697"""
698- permutedims(df::AbstractDataFrame, src_namescol::Union{Int, Symbol, AbstractString},
698+ permutedims(df::AbstractDataFrame,
699+ [src_namescol::Union{Int, Symbol, AbstractString}],
699700 [dest_namescol::Union{Symbol, AbstractString}];
700701 makeunique::Bool=false, strict::Bool=true)
701702
@@ -707,21 +708,25 @@ with name specified by `dest_namescol`.
707708# Arguments
708709- `df` : the `AbstractDataFrame`
709710- `src_namescol` : the column that will become the new header.
711+ If omitted then column names `:x1`, `:x2`, ... are generated automatically.
710712- `dest_namescol` : the name of the first column in the returned `DataFrame`.
711713 Defaults to the same name as `src_namescol`.
714+ Not supported when `src_namescol` is a vector or is omitted.
712715- `makeunique` : if `false` (the default), an error will be raised
713716 if duplicate names are found; if `true`, duplicate names will be suffixed
714717 with `_i` (`i` starting at 1 for the first duplicate).
718+ Not supported when `src_namescol` is omitted.
715719- `strict` : if `true` (the default), an error will be raised if the values
716720 contained in the `src_namescol` are not all `Symbol` or all `AbstractString`,
717721 or can all be converted to `String` using `convert`. If `false`
718722 then any values are accepted and the will be changed to strings using
719723 the `string` function.
724+ Not supported when `src_namescol` is a vector or is omitted.
720725
721726Note: The element types of columns in resulting `DataFrame`
722- (other than the first column, which always has element type `String`)
723- will depend on the element types of _all_ input columns
724- based on the result of `promote_type`.
727+ (other than the first column if it is created from `df` column names,
728+ which always has element type `String`) will depend on the element types of
729+ _all_ input columns based on the result of `promote_type`.
725730That is, if the source data frame contains `Int` and `Float64` columns,
726731resulting columns will have element type `Float64`. If the source has
727732`Int` and `String` columns, resulting columns will have element type `Any`.
@@ -732,6 +737,30 @@ column-level metadata is dropped.
732737# Examples
733738
734739```jldoctest
740+ julia> df = DataFrame(a=1:2, b=3:4)
741+ 2×2 DataFrame
742+ Row │ a b
743+ │ Int64 Int64
744+ ─────┼──────────────
745+ 1 │ 1 3
746+ 2 │ 2 4
747+
748+ julia> permutedims(df)
749+ 2×2 DataFrame
750+ Row │ x1 x2
751+ │ Int64 Int64
752+ ─────┼──────────────
753+ 1 │ 1 2
754+ 2 │ 3 4
755+
756+ julia> permutedims(df, [:p, :q])
757+ 2×2 DataFrame
758+ Row │ p q
759+ │ Int64 Int64
760+ ─────┼──────────────
761+ 1 │ 1 2
762+ 2 │ 3 4
763+
735764julia> df1 = DataFrame(a=["x", "y"], b=[1.0, 2.0], c=[3, 4], d=[true, false])
7367652×4 DataFrame
737766 Row │ a b c d
@@ -821,3 +850,7 @@ function Base.permutedims(df::AbstractDataFrame, src_namescol::ColumnIndex;
821850 return permutedims (df, src_namescol, dest_namescol;
822851 makeunique= makeunique, strict= strict)
823852end
853+
854+ Base. permutedims (df:: AbstractDataFrame ) = DataFrame (permutedims (Matrix (df)), :auto )
855+ Base. permutedims (df:: AbstractDataFrame , cnames:: AbstractVector ; makeunique:: Bool = false ) =
856+ DataFrame (permutedims (Matrix (df)), cnames, makeunique= makeunique)
0 commit comments