PHP code example of nagyatka / php-dataframe
1. Go to this page and download the library: Download nagyatka/php-dataframe library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nagyatka / php-dataframe example snippets
>>> $df = new DataFrame([[0,1],[2,3]]);
>>> print($df);
|0 |1 |
============================
0 |0 |1 |
1 |2 |3 |
Shape: 2x2
>>> $df = new DataFrame([[0,1],[2,3]], ["a", "b"]);
>>> print($df);
|a |b |
============================
0 |0 |1 |
1 |2 |3 |
Shape: 2x2
>>> $df = new DataFrame([[0,1],[2,3]], ["a", "b"], ["e", "f"]);
>>> print($df);
|a |b |
============================
e |0 |1 |
f |2 |3 |
Shape: 2x2
>>> $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
)
)
>>> $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
>>> 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
>>> 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
>>> $df = new DataFrame([[0,1],[2,3]], ["a", "b"], ["e", "f"]);
>>> print($df["a"]);
Series(Name=a, length=2){[
e: 0,
f: 2,
]}
>>> $df = new DataFrame([[0,1],[2,3]], ["a", "b"], ["e", "f"]);
>>> print($df[0]);
Series(Name=a, length=2){[
e: 0,
f: 2,
]}
>>> $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
>>> $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
>>> $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,
]}
>>> $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,
]}
>>> $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
>>> $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