PHPackages                             dcabrio/dataframe - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dcabrio/dataframe

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dcabrio/dataframe
=================

Archon: PHP Data Analysis Library

074PHP

Since Sep 30Pushed 3y agoCompare

[ Source](https://github.com/dcabrio/Archon-updated)[ Packagist](https://packagist.org/packages/dcabrio/dataframe)[ RSS](/packages/dcabrio-dataframe/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Archon: PHP Data Analysis Library
=================================

[](#archon-php-data-analysis-library)

[![Build Status](https://camo.githubusercontent.com/09085358ef29715a5f1f7b2aa247b7240763b212a7055d23053d96a5cd1965e4/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f485747656872696e672f417263686f6e2e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/HWGehring/Archon)[![Coverage Status](https://camo.githubusercontent.com/4fda4e9441a6d5b51d6d68eacaa65751146003af68ae3e3f4c4e1d2f7e8494ec/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f485747656872696e672f417263686f6e2e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/github/HWGehring/Archon?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/de34bf813806eefe6d3b42a1a3acad1ab3439126c43dcaa0eb9d854a90369e61/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f617263686f6e2f646174616672616d652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/archon/dataframe)[![License](https://camo.githubusercontent.com/72e937dcdd382658eb32422738fe60d3be26be97f9f0bb324870d9d00b57f3e8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f617263686f6e2f646174616672616d652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/archon/dataframe)

Archon is a PHP library designed to make working with tabular/relational data, files, and databases easy. The core component of the library is the DataFrame class - a tabular data structure which raises the level of abstraction when working with tabular, two-dimensional data.

Installation
------------

[](#installation)

### Using Composer:

[](#using-composer)

```
composer require dcabrio/dataframe dev-master
```

```
{
    "require": {
        "archon/dataframe": "1.1.1"
    }
}
```

### Requirements

[](#requirements)

- PHP 7.1 or higher
- php\_pdo\_sqlite extension
- php\_mbstring extension

### Dependencies

[](#dependencies)

- [PHPOffice/PHPExcel](https://github.com/PHPOffice/PHPExcel): 1.8.1
- [gajus/dindent](https://github.com/gajus/dindent): 2.0.2

### License

[](#license)

- [BSD-3-Clause](http://opensource.org/licenses/BSD-3-Clause)

Data Format Examples
--------------------

[](#data-format-examples)

### Instantiating from an array:

[](#instantiating-from-an-array)

```
$df = DataFrame::fromArray([
    ['a' => 1, 'b' => 2, 'c' => 3],
    ['a' => 4, 'b' => 5, 'c' => 6],
    ['a' => 7, 'b' => 8, 'c' => 9],
]);
```

### Reading a CSV file:

[](#reading-a-csv-file)

```
x|y|z
1|2|3
4|5|6
7|8|9

```

```
$df = DataFrame::fromCSV($fileName, [
    'sep' => '|',
    'colmap' => [
	    'x' => 'a',
        'y' => 'b',
        'z' => 'c'
    ]
]);
```

### Writing a CSV file:

[](#writing-a-csv-file)

```
$df->toCSV($fileName);
```

```
"a","b","c"
"1","2","3"
"4","5","6"
"7","8","9"

```

### Reading a fixed-width file:

[](#reading-a-fixed-width-file)

```
foo bar baz
-----------
1   2   3
4   5   6
7   8   9

```

```
$df = DataFrame::fromFWF($fileName, [
	'a' => [0, 1],
    'b' => [4, 5],
    'c' => [8, 9]
], ['include' => '^[0-9]']);
```

### Reading an XLSX spreadsheet:

[](#reading-an-xlsx-spreadsheet)

```
$dfA = DataFrame::fromXLSX($fileName, ['sheetname' => 'Sheet A']);
$dfB = DataFrame::fromXLSX($fileName, ['sheetname' => 'Sheet B']);
$dfC = DataFrame::fromXLSX($fileName, ['sheetname' => 'Sheet C']);
```

### Writing an XLSX spreadsheet:

[](#writing-an-xlsx-spreadsheet)

```
$phpExcel = new PHPExcel();
$dfA->toXLSXWorksheet($phpExcel, 'Sheet A');
$dfB->toXLSXWorksheet($phpExcel, 'Sheet B');
$dfC->toXLSXWorksheet($phpExcel, 'Sheet C');
$writer = new PHPExcel_Writer_Excel2007($phpExcel);
$writer->save($fileName);
```

### Querying from a database:

[](#querying-from-a-database)

```
$pdo = new PDO('sqlite::memory:');
$df = DataFrame::fromSQL('SELECT foo, bar, baz FROM table_name;', $pdo);
```

### Committing to a database:

[](#committing-to-a-database)

```
$pdo = new PDO('sqlite::memory:');
$affected = $df->toSQL('table_name', $pdo);
echo sprintf('%d rows committed to database.', $affected);
```

### Displaying an HTML table:

[](#displaying-an-html-table)

```
$html = $df->toHTML(['class' => 'myclass', 'id' => 'myid']);
```

abcabc123456789With support for [DataTables.js](http://datatables.net/):

```
$dataTable = $df->toHTML(['datatable' => '{ "optionKey": "optionValue" }']);
```

### Converting to JSON:

[](#converting-to-json)

```
$json = $df->toJSON();
```

### Creating from JSON:

[](#creating-from-json)

```
$df = DataFrame::fromJSON('[
    {"a": 1, "b": 2, "c": 3},
    {"a": 4, "b": 5, "c": 6},
    {"a": 7, "b": 8, "c": 9}
]');
```

### Extracting the underlying two-dimensional array:

[](#extracting-the-underlying-two-dimensional-array)

```
$myArray = $df->toArray();
print_r($myArray);
```

```
Array
(
    [0] => Array
        (
            [a] => 1
            [b] => 2
            [c] => 3
        )

    [1] => Array
        (
            [a] => 4
            [b] => 5
            [c] => 6
        )

    [2] => Array
        (
            [a] => 7
            [b] => 8
            [c] => 9
        )

)
```

Basic Operations
----------------

[](#basic-operations)

Getting column names:

```
$df->columns()
--------------
Array
(
    [0] => a
    [1] => b
    [2] => c
)
```

Adding columns:

```
$df['key'] = 'value';
```

Removing columns:

```
unset($df['key']);
```

Counting rows:

```
count($df);
```

Iterating over rows:

```
foreach ($df as $i => $row) {
   echo $i.': '.implode('-', $row).PHP_EOL;
}
--------------------------
0: 1-2-3
1: 4-5-6
2: 7-8-9
```

Advanced Operations
-------------------

[](#advanced-operations)

Applying functions to rows:

```
$df = $df->apply(function ($row, $index) {
    $row['a'] = $row['c'] + 1;
    return $row;
});
```

Applying functions to columns directly:

```
$df['a'] = function ($el, $key) {
    return $el + 3;
};
```

Applying values to columns via function application of other columns:

```
$df['a'] = $df['c']->apply(function ($el, $key) {
    return $el + 1;
});
```

Applying types:

```
$df = DataFrame::fromArray([
    ['my_date'           => '11/20/16'],
    ['my_other_date'     => '2/12/2016'],
    ['my_decimal'        => '5,000.20'],
    ['my_int'            => '10-'],
    ['my_currency'       => '12345.67']
]);

$df->convertTypes([
    'my_date'       => 'DATE',
    'my_other_date' => 'DATE',
    'my_decimal'    => 'DECIMAL',
    'my_int'        => 'INT',
    'my_currency'   => 'CURRENCY'
], ['m/d/y', 'd/m/Y'], 'Y-m-d');

print_r($df->toArray());
```

```
Array
(
    [0] => Array
        (
            [my_date] => '2016-11-20'
            [my_other_date] => '2016-12-2'
            [my_decimal] => '5000.20'
            [my_int] => '-10'
            [my_currency] => '$12,345.67'
        )

)
```

Manipulating DataFrame using SQL:

```
$df = DataFrame::fromArray([
    ['a' => 1, 'b' => 2, 'c' => 3],
    ['a' => 4, 'b' => 5, 'c' => 6],
    ['a' => 7, 'b' => 8, 'c' => 9],
]);

$df = $df->query("

SELECT
  a,
  b
FROM dataframe
WHERE a = '4'
  OR b = '2';

");

print_r($df->toArray());
```

```
Array
(
    [0] => Array
        (
            [a] => 1
            [b] => 2
        )

    [1] => Array
        (
            [a] => 4
            [b] => 5
        )

)
```

```
$df = DataFrame::fromArray([
    ['a' => 1, 'b' => 2, 'c' => 3],
    ['a' => 4, 'b' => 5, 'c' => 6],
    ['a' => 7, 'b' => 8, 'c' => 9],
]);

$df = $df->query("

UPDATE dataframe
SET a = c * 2;

");

print_r($df['a']->to_array());
```

```
Array
(
    [0] => Array
        (
            [a] => 6
        )

    [1] => Array
        (
            [a] => 12
        )

    [2] => Array
        (
            [a] => 18
        )

)
```

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 Bus Factor1

Top contributor holds 98% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/5e6ae4adbd11202cf47b30ede40b37359bc0b3b9c4946b3478e4f4a6a8c2438d?d=identicon)[dcabrio](/maintainers/dcabrio)

---

Top Contributors

[![hwperkins](https://avatars.githubusercontent.com/u/1647648?v=4)](https://github.com/hwperkins "hwperkins (147 commits)")[![dcabrio](https://avatars.githubusercontent.com/u/114672816?v=4)](https://github.com/dcabrio "dcabrio (1 commits)")[![mrahmadt](https://avatars.githubusercontent.com/u/957921?v=4)](https://github.com/mrahmadt "mrahmadt (1 commits)")[![remibaar](https://avatars.githubusercontent.com/u/1812184?v=4)](https://github.com/remibaar "remibaar (1 commits)")

### Embed Badge

![Health badge](/badges/dcabrio-dataframe/health.svg)

```
[![Health](https://phpackages.com/badges/dcabrio-dataframe/health.svg)](https://phpackages.com/packages/dcabrio-dataframe)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
