PTable
public struct PTable
extension PTable: CustomStringConvertible
extension PTable: Equatable
A collection of named PColumns.
A PTable, also known as a data frame, represents a tabular collection of data.
Invariants:
- Each column must have the same number of elements.
- Column names are unique.
-
Initializes a
PTablefrom a sequence ofString,PColumnpairs.Throws
PError.colCountMisMatchif the column lengths are not equal.Throws
PError.duplicateColumnNameif the name of a column is duplicated.Declaration
Swift
public init(_ columns: [(String, PColumn)]) throws -
Initializes a
PTablefrom a dictionary mapping fromStrings toPColumns.Throws
PError.colCountMisMatchif the column lengths are not equal.Declaration
Swift
public init(_ columns: [String : PColumn]) throws -
Selects a subset of columns to form a new
PTable.Declaration
Swift
public subscript(columnNames: [String]) -> PTable { get }Parameters
columnNamesThe list of column names to include in the new
PTable. Each element must be unique, and must refer to a valid column in thisPTable. -
Builds a new
PTableselecting only rows set in the index set.Declaration
Swift
public subscript(indexSet: PIndexSet) -> PTable { get }Parameters
indexSet -
Access an element at a given row and column.
Note: this subscript operation is generic over the return type; as a result you need to tell Swift what type you expect to come out based on your knowledge of the storage type of the underlying column. See the following example:
var myValue: Double = myTable["myColumnOfDoubles", 23] myValue += 103 myTable["myColumnOfDoubles", 23] = myValueNote: although this is an O(1) operation, it is relatively inefficient. If you need to compute a result over a large number of rows, look at the writing your operation against a
PTypedColumntype instead.Declaration
Swift
public subscript<T>(columnName: String, index: Int) -> T? where T : PCSVParsible, T : PDefaultInit, T : PStringParsible, T : Comparable, T : Hashable { get set }Parameters
columnNameThe name of the column to access.
indexThe offset into the column to access.
-
The names of the columns contained in this
PTable.Declaration
Swift
public var columnNames: [String] { get set } -
Rename a column.
Declaration
Swift
public mutating func rename(_ col: String, to newName: String) throwsParameters
colThe name of the column currently.
newNameThe new name of the column.
-
Drops columns.
This is the safe variation of
drop(_:), which will throw an error if there is a problem with a provided column name.Note: this function is implemented such that it either fully succeeds or throws an error, and will never leave the Table in an inconsistent state.
Declaration
Swift
public mutating func drop(columns: String...) throws -
Drops columns.
If a column name does not exist in the PTable, it is silently ignored.
Declaration
Swift
public mutating func drop(_ columns: String...) -
Drops rows that contain nils.
Declaration
Swift
public mutating func dropNils(columns: [String]? = nil)Parameters
columnsif
nil(default), filtering occurs over all columns, otherwise only rows containing nils in the specified subset of columns are dropped. -
Returns a new
PTablewhere rows containing nils have been dropped.Declaration
Swift
public func droppedNils(columns: [String]? = nil) -> PTableParameters
columnsif
nil(default), filtering occurs over all columns, otherwise only rows containing nils in the specified subset of columns are dropped. -
Sorts the
PTable(in place) based on elements in the named column.This sort is guaranteed to be stable, such that if the elements of column
columnNameare equal, than they will appear in the same order after sorting as before.Declaration
Swift
public mutating func sort(by columnName: String, ascending order: Bool = true)Parameters
columnNameThe name of the column to use to sort.
ordertrue(default) for ascending, false for descending. -
Sorts the
PTable(in place) based on elements in the named columns.This sort is guaranteed to be stable.
Declaration
Swift
public mutating func sort( by columnName1: String, ascending c1Order: Bool = true, _ columnName2: String, ascending c2Order: Bool = true )Parameters
columnName1The name of the first column to use to sort.
c1Ordertruefor ascending ordering ofcolumnName1, false otherwise.columnName2The name of the second column to use to sort.
c2Ordertruefor ascending ordering ofcolumnName2, false otherwise. -
Undocumented
Declaration
Swift
public func sorted(by columnName: String, ascending: Bool = true) -> PTable -
Undocumented
Declaration
Swift
public func sorted( by c1: String, ascending c1Order: Bool = true, _ c2: String, ascending c2Order: Bool = true ) -> PTable -
Perform a “group-by” operation, reducing the groups with aggregations.
Declaration
Swift
public func group( by column: String, applying aggregations: Aggregation... ) throws -> PTableParameters
columnGroup rows in
PTablebased on elements in this column.aggregationsThe set of aggregations to apply.
-
Perform a “group-by” operation, reducing the groups with aggregations.
Declaration
Swift
public func group( by columnNames: [String], applying aggregations: Aggregation... ) throws -> PTableParameters
columnNamesGroup rows in
PTablebased on elements in these columns.aggregationsThe set of aggregations to apply.
-
Perform a “group-by” operation, reducing the groups with aggregations.
Declaration
Swift
public func group( by columnNames: [String], applying aggregations: [Aggregation] ) throws -> PTableParameters
columnNamesGroup rows in
PTablebased on elements in these columns.aggregationsThe set of aggregations to apply.
-
Undocumented
Declaration
Swift
public mutating func joined(with other: PTable, onColumn joinColumnName: String) throws -
Undocumented
Declaration
Swift
public func join(with other: PTable, onColumn joinColumnName: String) throws -> PTable -
The number of rows contained within the
PTable.If there are no
PColumns in the table,countreturnsnil.Declaration
Swift
public var count: Int? { get } -
Computes summaries for each column contained within this
PTable.Declaration
Swift
public func summarize() -> [(String, PColumnSummary)] -
A string representation of a (subset) of the table.
Declaration
Swift
public var description: String { get } -
Returns true iff
lhsandrhscontain identical data, false otherwise.Declaration
Swift
public static func == (lhs: PTable, rhs: PTable) -> Bool -
Undocumented
Declaration
Swift
public init(csv file: String) throws -
Undocumented
Declaration
Swift
public func tmap< O: ElementRequirements, T1: ElementRequirements >( _ c1: String, fn: (T1) throws -> O ) rethrows -> PTypedColumn<O> -
Undocumented
Declaration
Swift
public func tmap< O: ElementRequirements, T1: ElementRequirements, T2: ElementRequirements >( _ c1: String, _ c2: String, fn: (T1, T2) throws -> O ) rethrows -> PTypedColumn<O> -
Undocumented
Declaration
Swift
public func tmap< O: ElementRequirements, T1: ElementRequirements, T2: ElementRequirements, T3: ElementRequirements >( _ c1: String, _ c2: String, _ c3: String, fn: (T1, T2, T3) throws -> O ) rethrows -> PTypedColumn<O> -
Undocumented
Declaration
Swift
public func tmap< O: ElementRequirements, T1: ElementRequirements, T2: ElementRequirements, T3: ElementRequirements, T4: ElementRequirements >( _ c1: String, _ c2: String, _ c3: String, _ c4: String, fn: (T1, T2, T3, T4) throws -> O ) rethrows -> PTypedColumn<O> -
Undocumented
Declaration
Swift
public func tmap< O: ElementRequirements, T1: ElementRequirements, T2: ElementRequirements, T3: ElementRequirements, T4: ElementRequirements, T5: ElementRequirements >( _ c1: String, _ c2: String, _ c3: String, _ c4: String, _ c5: String, fn: (T1, T2, T3, T4, T5) throws -> O ) rethrows -> PTypedColumn<O> -
Undocumented
Declaration
Swift
public func tmap< O: ElementRequirements, T1: ElementRequirements, T2: ElementRequirements, T3: ElementRequirements, T4: ElementRequirements, T5: ElementRequirements, T6: ElementRequirements >( _ c1: String, _ c2: String, _ c3: String, _ c4: String, _ c5: String, _ c6: String, fn: (T1, T2, T3, T4, T5, T6) throws -> O ) rethrows -> PTypedColumn<O>
View on GitHub
PTable Structure Reference