@@ -61,8 +61,12 @@ abstract type AbstractDataFrame end
6161# #############################################################################
6262
6363"""
64- names(df::AbstractDataFrame)
65- names(df::AbstractDataFrame, cols)
64+ names(df::AbstractDataFrame, cols=:)
65+ names(df::DataFrameRow, cols=:)
66+ names(df::GroupedDataFrame, cols=:)
67+ names(df::DataFrameRows, cols=:)
68+ names(df::DataFrameColumns, cols=:)
69+ names(df::GroupKey)
6670
6771Return a freshly allocated `Vector{String}` of names of columns contained in `df`.
6872
@@ -76,6 +80,51 @@ selector (this is useful in particular with regular expressions, `Cols`, `Not`,
7680 for columns that should be kept
7781
7882See also [`propertynames`](@ref) which returns a `Vector{Symbol}`.
83+
84+ # Examples
85+ ```jldoctest
86+ julia> df = DataFrame(x1=[1, missing, missing], x2=[3, 2, 4], x3=[3, missing, 2], x4=Union{Int, Missing}[2, 4, 4])
87+ 3×4 DataFrame
88+ Row │ x1 x2 x3 x4
89+ │ Int64? Int64 Int64? Int64?
90+ ─────┼─────────────────────────────────
91+ 1 │ 1 3 3 2
92+ 2 │ missing 2 missing 4
93+ 3 │ missing 4 2 4
94+
95+ julia> names(df)
96+ 4-element Vector{String}:
97+ "x1"
98+ "x2"
99+ "x3"
100+ "x4"
101+
102+ julia> names(df, Int) # pick columns whose element type is Int
103+ 1-element Vector{String}:
104+ "x2"
105+
106+ julia> names(df, x -> x[end] == '2') # pick columns for which last character in their name is '2'
107+ 1-element Vector{String}:
108+ "x2"
109+
110+ julia> fun(col) = sum(skipmissing(col)) >= 10
111+ fun (generic function with 1 method)
112+
113+ julia> names(df, fun.(eachcol(df))) # pick columns for which sum of their elements is at least 10
114+ 1-element Vector{String}:
115+ "x4"
116+
117+ julia> names(df, eltype.(eachcol(df)) .>: Missing) # pick columns that allow missing values
118+ 3-element Vector{String}:
119+ "x1"
120+ "x3"
121+ "x4"
122+
123+ julia> names(df, any.(ismissing, eachcol(df))) # pick columns that contain missing values
124+ 2-element Vector{String}:
125+ "x1"
126+ "x3"
127+ ```
79128"""
80129Base. names (df:: AbstractDataFrame , cols:: Colon = :) = names (index (df))
81130
0 commit comments