DataFrame
- Full name:
\MammothPHP\WoollyM\DataFrame
- Parent class:
\MammothPHP\WoollyM\DataFrameHelpers
Methods
fromArray
Factory method for creating a DataFrame from a two-dimensional associative array.
public static fromArray(array $data): static
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$data | array |
Inherited methods
insert
Return an Update statement, methods will return the same DataFrame object
public insert(): \MammothPHP\WoollyM\Statements\Insert\Insert
__construct
public __construct(array<int,array> $data = [], mixed $dataDriver = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$data | array<int,array> | Array data to ingest |
$dataDriver | mixed | - Class of custom driver to use. if null, the PhpArray (in-memory) driver will used. |
Throws:
__clone
public __clone(): mixed
addColumn
Adds a new column to the DataFrame. If column already exist, then nothing will happen.
public addColumn(string $columnName): static
Parameters:
Parameter | Type | Description |
---|---|---|
$columnName | string |
addColumns
Adds multiple columns to the DataFrame.
public addColumns(string[] $columnNames): static
Parameters:
Parameter | Type | Description |
---|---|---|
$columnNames | string[] |
removeColumn
Removes a column (and all associated data) from the DataFrame.
public removeColumn(string $columnName): static
Parameters:
Parameter | Type | Description |
---|---|---|
$columnName | string |
hasColumn
Returns a boolean of whether the specified column exists.
public hasColumn(\MammothPHP\WoollyM\Statements\Select\ColumnRepresentation|string $column): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$column | \MammothPHP\WoollyM\Statements\Select\ColumnRepresentation|string |
countColumns
Count unique columns already known
public countColumns(): int
columns
Return ColumnRepresentation Object extending Select object
public columns(): array<int,\MammothPHP\WoollyM\Statements\Select\ColumnRepresentation>
columnsNames
Get unique columns already known
public columnsNames(): array<int,string>
mustHaveColumn
Assertion that the DataFrame must have the column specified. If not then an exception is thrown.
public mustHaveColumn(string $columnName): static
Parameters:
Parameter | Type | Description |
---|---|---|
$columnName | string |
Throws:
getColumnKey
protected getColumnKey(string $columnName): int
Parameters:
Parameter | Type | Description |
---|---|---|
$columnName | string |
createColumnRepresentation
protected createColumnRepresentation(\MammothPHP\WoollyM\ColumnIndex $columnIndex): void
Parameters:
Parameter | Type | Description |
---|---|---|
$columnIndex | \MammothPHP\WoollyM\ColumnIndex |
addRecord
Add a record, providing an array indexed by column => value
public addRecord(array<string,mixed> $recordArray): static
Parameters:
Parameter | Type | Description |
---|---|---|
$recordArray | array<string,mixed> |
updateRecord
Update a record by record key. If key does not exist, record will be created.
public updateRecord(int $key, array $recordArray): static
Parameters:
Parameter | Type | Description |
---|---|---|
$key | int | |
$recordArray | array |
updateCell
public updateCell(int $recordKey, string $column, mixed $newValue): static
Parameters:
Parameter | Type | Description |
---|---|---|
$recordKey | int | |
$column | string | |
$newValue | mixed |
removeRecord
Remove a record by key
public removeRecord(int $key): static
Parameters:
Parameter | Type | Description |
---|---|---|
$key | int |
Throws:
getRecord
Get a record by key
public getRecord(int $key): array<string,array>
Parameters:
Parameter | Type | Description |
---|---|---|
$key | int |
getRecordAsArray
Get a record by key and return an array
public getRecordAsArray(int $key): array<string,array>
Parameters:
Parameter | Type | Description |
---|---|---|
$key | int |
recordKeyExist
Check if a record key exist
public recordKeyExist(int $recordKey): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$recordKey | int |
convertRecordToAbstract
protected convertRecordToAbstract(array $recordArray): array
Parameters:
Parameter | Type | Description |
---|---|---|
$recordArray | array |
convertAbstractToRecordObject
protected convertAbstractToRecordObject(array $abstractRecord): \MammothPHP\WoollyM\Record
Parameters:
Parameter | Type | Description |
---|---|---|
$abstractRecord | array |
toArray
Outputs a DataFrame as a two-dimensional associative array.
public toArray(bool $fillInNonExistentCol = false): array
Parameters:
Parameter | Type | Description |
---|---|---|
$fillInNonExistentCol | bool |
initDriverIterator
protected initDriverIterator(): void
getRecordsAsArrayIterator
public getRecordsAsArrayIterator(bool $fillAllColumn = false): \Iterator
Parameters:
Parameter | Type | Description |
---|---|---|
$fillAllColumn | bool |
select
Return a Select object
public select(string[] $selections): \MammothPHP\WoollyM\Statements\Select\Select
Parameters:
Parameter | Type | Description |
---|---|---|
$selections | string[] | column(s) name(s) to select |
selectAll
Return a fixed selectAll object
public selectAll(): \MammothPHP\WoollyM\Statements\Select\SelectAll
col
Return a ColumnRepresentation object, extending Select object.
public col(string $columnName): \MammothPHP\WoollyM\Statements\Select\ColumnRepresentation
Parameters:
Parameter | Type | Description |
---|---|---|
$columnName | string |
Throws:
column
Alias for col() method.
public column(string $columnName): \MammothPHP\WoollyM\Statements\Select\ColumnRepresentation
Parameters:
Parameter | Type | Description |
---|---|---|
$columnName | string |
extract
Return a Copy object, methods will return new DataFrame objects.
public extract(\MammothPHP\WoollyM\DataFrame $to = new DataFrame()): \MammothPHP\WoollyM\Extract
Parameters:
Parameter | Type | Description |
---|---|---|
$to | \MammothPHP\WoollyM\DataFrame |
delete
Return a Copy object, methods will return new DataFrame objects.
public delete(): \MammothPHP\WoollyM\Statements\Delete\Delete
update
Return an Update statement, methods will return the same DataFrame object
public update(): \MammothPHP\WoollyM\Statements\Update\Update
sortColumns
Sort column order using a closure. Then retrieve records will respect the new order.
public sortColumns(mixed $callback = null): static
Parameters:
Parameter | Type | Description |
---|---|---|
$callback | mixed | - If null, sort will be alphabetic. For closure, example fn(string $a, string $b): int => $a <=> $b; |
sortRecordsByColumns
Sort the records by columns
public sortRecordsByColumns(array|string $by, bool $ascending = true): static
Parameters:
Parameter | Type | Description |
---|---|---|
$by | array|string | |
$ascending | bool |
count
Count records
public count(): int
head
Return the the first records
public head(mixed $length = 5, mixed $offset, mixed $columns = null): array
Parameters:
Parameter | Type | Description |
---|---|---|
$length | mixed | - Number of records |
$offset | mixed | - Start at record number x (from 0) |
$columns | mixed | - Only these columns |
Throws:
groupBy
public groupBy(string[] $args): \MammothPHP\WoollyM\DataFrame
Parameters:
Parameter | Type | Description |
---|---|---|
$args | string[] |
Automatically generated on 2024-07-03