PHPackages                             nagyatka/php-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. nagyatka/php-dataframe

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

nagyatka/php-dataframe
======================

library for table editing

v0.1.1(5y ago)1222[1 issues](https://github.com/nagyatka/php-dataframe/issues)MITPHPPHP ^7.2

Since Jan 1Pushed 5y ago2 watchersCompare

[ Source](https://github.com/nagyatka/php-dataframe)[ Packagist](https://packagist.org/packages/nagyatka/php-dataframe)[ RSS](/packages/nagyatka-php-dataframe/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

php-dataframe
=============

[](#php-dataframe)

A lightweight dataframe handling package for php.

The php-dataframe package is not a data science package, it just tries copy the main features of pandas' DataFrame.

Software requirements
---------------------

[](#software-requirements)

PHP version 7.2 or newer to develop using php-dataframe.

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

[](#installation)

Use [composer](https://getcomposer.org) to install PhpSpreadsheet into your project:

```
composer require nagyatka/php-dataframe
```

Usage
-----

[](#usage)

### Create DataFrame

[](#create-dataframe)

#### Create a simple DataFrame object using a 2D array:

[](#create-a-simple-dataframe-object-using-a-2d-array)

```
>>> $df = new DataFrame([[0,1],[2,3]]);
>>> print($df);

     |0         |1         |
============================
0    |0         |1         |
1    |2         |3         |
Shape: 2x2
```

#### Create a simple DataFrame object using a 2D array, and column names:

[](#create-a-simple-dataframe-object-using-a-2d-array-and-column-names)

```
>>> $df = new DataFrame([[0,1],[2,3]], ["a", "b"]);
>>> print($df);

     |a         |b         |
============================
0    |0         |1         |
1    |2         |3         |
Shape: 2x2
```

#### Create a simple DataFrame object using a 2D array, column names, and indices:

[](#create-a-simple-dataframe-object-using-a-2d-array-column-names-and-indices)

```
>>> $df = new DataFrame([[0,1],[2,3]], ["a", "b"], ["e", "f"]);
>>> print($df);

     |a         |b         |
============================
e    |0         |1         |
f    |2         |3         |
Shape: 2x2
```

### Get DataFrame's basic information

[](#get-dataframes-basic-information)

A DataFrame stores a 2D php array and the associated column names and indices.

#### Access to the raw 2D array

[](#access-to-the-raw-2d-array)

```
>>> $df = new DataFrame([[0,1,2], [3,4,5]], ["a", "b", "c"], ["e", "f"]);
>>> print_r($df->values);

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

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

)
```

#### Get shape information

[](#get-shape-information)

```
>>> $df = new DataFrame([[0,1,2], [3,4,5]], ["a", "b", "c"], ["e", "f"]);
>>> print("Number of rows: " . $df->shape[0]);
Number of rows: 2
>>> print("Number of columns: " . $df->shape[1]);
Number of columns: 3
```

#### Get/Set column names

[](#getset-column-names)

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

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

>>> $df->setColumnNames(["x", "y", "z"]);
>>> print($df);

     |x         |y         |z         |
=======================================
e    |0         |1         |2         |
f    |3         |4         |5         |
Shape: 2x3
```

#### Get/Set indices

[](#getset-indices)

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

Array
(
    [0] => e
    [1] => f
)

>>> $df->setIndices(["p", "q"]);
>>> print($df);

     |x         |y         |z         |
=======================================
p    |0         |1         |2         |
q    |3         |4         |5         |
Shape: 2x3
```

### Indexing and selecting data

[](#indexing-and-selecting-data)

#### Selecting one column of a DataFrame

[](#selecting-one-column-of-a-dataframe)

Selecting column `"a"`, the DataFrame object returns with a Series object.

```
>>> $df = new DataFrame([[0,1],[2,3]], ["a", "b"], ["e", "f"]);
>>> print($df["a"]);

Series(Name=a, length=2){[
	e: 0,
	f: 2,
]}
```

Selecting a column by column's index also works

```
>>> $df = new DataFrame([[0,1],[2,3]], ["a", "b"], ["e", "f"]);
>>> print($df[0]);

Series(Name=a, length=2){[
	e: 0,
	f: 2,
]}
```

#### Selecting multiple columns of a DataFrame

[](#selecting-multiple-columns-of-a-dataframe)

Because php does not support array object as key, the `cols` helper function needs to be used to select multi columns.

```
>>> $df = new DataFrame([[0,1,2], [3,4,5]], ["a", "b", "c"], ["e", "f"]);
>>> print($df[\PHPDataFrame\cols(["b", "c"])]);

     |b         |c         |
============================
e    |1         |2         |
f    |4         |5         |
Shape: 2x2
```

You can also use column indices to get a sub DataFrame:

```
>>> $df = new DataFrame([[0,1,2], [3,4,5]], ["a", "b", "c"], ["e", "f"]);
>>> print($df[\PHPDataFrame\cols([0,1])]);

     |a         |b         |
============================
e    |0         |1         |
f    |3         |4         |
Shape: 2x2
```

#### Selecting one row of a DataFrame

[](#selecting-one-row-of-a-dataframe)

You can select one row of a DataFrame using `iloc` operator.

```
>>> $df = new DataFrame([[0,1,2], [3,4,5]], ["a", "b", "c"], ["e", "f"]);
>>> print($df->iloc["e"]);

Series(Index=e, Length=3){[
	a: 0,
	b: 1,
	c: 2,
]}
```

Of course, numeric indices can be used as well.

```
>>> $df = new DataFrame([[0,1,2], [3,4,5]], ["a", "b", "c"], ["e", "f"]);
>>> print($df->iloc[0]);

Series(Index=0, Length=3){[
	a: 0,
	b: 1,
	c: 2,
]}
```

#### Selecting multiple rows of a DataFrame

[](#selecting-multiple-rows-of-a-dataframe)

Because php does not support array object as key, the `inds` helper function needs to be used to select multi columns.

```
>>> $df = new DataFrame([[0,1,2], [3,4,5], [6,7,8]], ["a", "b", "c"], ["e", "f", "g"]);
>>> print($df->iloc[\PHPDataFrame\inds(["g","f"])]);

     |a         |b         |c         |
=======================================
g    |6         |7         |8         |
f    |3         |4         |5         |
Shape: 2x3

>>> print($df->iloc[\PHPDataFrame\inds([0,1])]);

     |a         |b         |c         |
=======================================
e    |0         |1         |2         |
f    |3         |4         |5         |
Shape: 2x3
```

Since the index values don't have to be unique, an `iloc` operation with a label index can results in multiple rows.

```
>>> $df = new DataFrame([[0,1,2], [3,4,5], [6,7,8]], ["a", "b", "c"], ["e", "f", "e"]);
>>> print($df->iloc["e"]);

     |a         |b         |c         |
=======================================
e    |0         |1         |2         |
e    |6         |7         |8         |
Shape: 2x3
```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1962d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3961400?v=4)[nagyatka](/maintainers/nagyatka)[@nagyatka](https://github.com/nagyatka)

---

Top Contributors

[![nagyatka](https://avatars.githubusercontent.com/u/3961400?v=4)](https://github.com/nagyatka "nagyatka (23 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[in2code/powermail

Powermail is a well-known, editor-friendly, powerful and easy to use mailform extension for TYPO3 with a lots of features

982.5M38](/packages/in2code-powermail)[blair2004/nexopos

The Free Modern Point Of Sale System build with Laravel, TailwindCSS and Vue.js.

1.2k2.3k](/packages/blair2004-nexopos)[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

52664.9k12](/packages/solspace-craft-freeform)[pimcore/data-importer

Adds a comprehensive import functionality to Pimcore Datahub

44763.4k2](/packages/pimcore-data-importer)[portphp/spreadsheet

PhpSpreadsheet reader and writer for Port

14796.4k4](/packages/portphp-spreadsheet)

PHPackages © 2026

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