Indexing
General rules
The following rules explain target functionality of how getindex, setindex!, and view are intended to work with DataFrame, SubDataFrame and DataFrameRow objects.
The rules for a valid type of index into a column are the following:
- a value, later denoted as
col:- a
Symbol; - an
Integerthat is notBool;
- a
- a vector, later denoted as
cols:- a vector of
Symbol(does not have to be a subtype ofAbstractVector{Symbol}); - a vector of
Integerother thanBool(does not have to be a subtype ofAbstractVector{<:Integer}); - a vector of
Boolthat has to be a subtype ofAbstractVector{Bool}. - a colon.
- a vector of
The rules for a valid type of index into a row are the following:
- a value, later denoted as
row:- an
Integerthat is notBool;
- an
- a vector, later denoted as
rows:- a vector of
Integerother thanBool(does not have to be a subtype ofAbstractVector{<:Integer}); - a vector of
Boolthat has to be a subtype ofAbstractVector{Bool}; - a colon.
- a vector of
In the descriptions below df represents a DataFrame, sdf is a SubDataFrame and dfr is a DataFrameRow.
getindex
The following list specifies return types of getindex operations depending on argument types.
In all operations copying vectors is avoided where possible. If it is performed a description explicitly mentions that the data is copied.
For performance reasons, accessing, via getindex or view, a single row and multiple cols of a DataFrame, a SubDataFrame or a DataFrameRow always returns a DataFrameRow (which is a view-like type).
DataFrame:
df[col]-> the vector contained in columncol;df[cols]-> a freshly allocatedDataFramecontaining the vectors contained in columnscols;df[row, col]-> the value contained in rowrowof columncol, the same asdf[col][row];df[row, cols]-> aDataFrameRowwith parentdfifcolsis a colon anddf[cols]otherwise;df[rows, col]-> a copy of the vectordf[col]with only the entries corresponding torowsselected, the same asdf[col][rows];df[rows, cols]-> aDataFramecontaining copies of columnscolswith only the entries corresponding torowsselected.@view df[col]-> the vector contained in columncol(this is equivalent todf[col]);@view df[cols]-> aSubDataFramewith parentdfifcolsis a colon anddf[cols]otherwise;@view df[row, col]-> a0-dimensional view intodf[col], the same asview(df[col], row);@view df[row, cols]-> aDataFrameRowwith parentdfifcolsis a colon anddf[cols]otherwise;@view df[rows, col]-> a view intodf[col]withrowsselected, the same asview(df[col], rows);@view df[rows, cols]-> aSubDataFramewithrowsselected with parentdfifcolsis a colon anddf[cols]otherwise.
SubDataFrame:
sdf[col]-> a view of the vector contained in columncolofparent(sdf)withDataFrames.rows(sdf)as a selector;sdf[cols]-> aSubDataFrame, with parentparent(sdf)ifcolsis a colon andparent(sdf)[cols]otherwise;sdf[row, col]-> a value contained in rowrowof columncol;sdf[row, cols]-> aDataFrameRowwith parentparent(sdf)ifcolsis a colon andparent(sdf)[cols]otherwise;sdf[rows, col]-> a copy of a vectorsdf[col]with only rowsrowsselected;sdf[rows, cols]-> aDataFramecontaining columnscolsanddf[rows, col]as a vector in eachcolincols.@view sdf[col]-> a view of vector contained in columncolofparent(sdf)withDataFrames.rows(sdf)as selector;@view sdf[cols]-> aSubDataFramewith parentparent(sdf)ifcolsis a colon andparent(sdf)[cols]otherwise;@view sdf[row, col]-> translates toview(sdf[col], row)(a0-dimensional view intodf[col]);@view sdf[row, cols]-> aDataFrameRowwith parentparent(sdf)ifcolsis a colon andparent(sdf)[cols]otherwise;@view sdf[rows, col]-> translates toview(sdf[col], rows)(a standard view intosdf[col]vector);@view sdf[rows, cols]-> aSubDataFramewith parentparent(sdf)ifcolsis a colon andsdf[cols]otherwise.
DataFrameRow:
dfr[col]-> the value contained in columncolofdfr;dfr[cols]-> aDataFrameRowwith parentparent(dfr)ifcolsis a colon andparent(dfr)[cols]otherwise;@view dfr[col]-> a0-dimensional view intoparent(dfr)[DataFrames.row(dfr), col];@view dfr[cols]-> aDataFrameRowwith parentparent(dfr)ifcolsis a colon andparent(dfr)[cols]otherwise;
setindex!
Under construction