Skip to content

Commit

Permalink
Merge branch 'feature/pandas-api-2nd-block' into feature/pandas-api-isin
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosvm13 authored Jan 22, 2024
2 parents 25fc39b + dad1e0b commit 5243ca4
Show file tree
Hide file tree
Showing 3 changed files with 657 additions and 2 deletions.
320 changes: 318 additions & 2 deletions docs/user-guide/advanced/Pandas_API.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,32 @@
"tab.size"
]
},
{
"cell_type": "markdown",
"id": "4023811f-0f23-4e4b-919c-c055b865d9d2",
"metadata": {},
"source": [
"### Table.values\n",
"Return a matricial representation of the DataFrame.\n",
"\n",
"Only the values in the DataFrame will be returned, the axes labels will be removed.\n",
"\n",
"**Returns:**\n",
"\n",
"| Type | Description |\n",
"| :---------------: | :------------------------------------------------------------------- |\n",
"| List | The values of the table as a matrix. |"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "a7843813-43fc-4920-acd9-6fd2dd50c32e",
"metadata": {},
"source": [
"tab.values"
]
},
{
"cell_type": "markdown",
"id": "2be2ece3",
Expand Down Expand Up @@ -436,6 +462,91 @@
"tab.mean(axis=1)"
]
},
{
"cell_type": "markdown",
"id": "fe565b65-fbf2-47ba-a26e-791d09fd4f55",
"metadata": {},
"source": [
"### Table.kurt()\n",
"\n",
"```\n",
"Table.kurt(axis=0, skipna=True, numeric_only=False)\n",
"```\n",
"\n",
"Return unbiased kurtosis over requested axis. Kurtosis obtained using Fisher’s definition of kurtosis (kurtosis of normal == 0.0). Normalized by N-1.\n",
"\n",
"\n",
"**Parameters:**\n",
"\n",
"| Name | Type | Description | Default |\n",
"| :----------: | :--: | :------------------------------------------------------------------------------- | :-----: |\n",
"| axis | int | Axis for the function to be applied on. 0 is columns, 1 is rows. | 0 |\n",
"| skipna | bool | not yet implemented | True |\n",
"| numeric_only | bool | Only use columns of the table that are of a numeric data type. | False |\n",
"\n",
"**Returns:**\n",
"\n",
"| Type | Description |\n",
"| :--------: | :--------------------------------------------------------------------------------------- |\n",
"| Dictionary | Map of columns and their yielded kurtosis values |"
]
},
{
"cell_type": "markdown",
"id": "e6069cac-d260-4f80-9688-3d1ec273cd22",
"metadata": {},
"source": [
"**Examples:**\n",
"\n",
"Calculate the kurt across the columns of a table"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4219c826-a84b-4722-9847-372d3837acdb",
"metadata": {},
"outputs": [],
"source": [
"tab = kx.Table(data=\n",
" {\n",
" 'a': [1, 2, 2, 4],\n",
" 'b': [1, 2, 6, 7],\n",
" 'c': [7, 8, 9, 10],\n",
" 'd': [7, 11, 14, 14]\n",
" }\n",
")\n",
"tab"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "437ab485-bf73-4209-b63e-aa0d1bfa5d58",
"metadata": {},
"outputs": [],
"source": [
"tab.kurt()"
]
},
{
"cell_type": "markdown",
"id": "ea3e1cf6-2304-4061-a846-1cbc0572ea9d",
"metadata": {},
"source": [
"Calculate the kurtosis across the rows of a table"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "63312e8b-76f0-46eb-b4d7-b2213561c86e",
"metadata": {},
"outputs": [],
"source": [
"tab.kurt(axis=1)"
]
},
{
"cell_type": "markdown",
"id": "7bf853c5",
Expand Down Expand Up @@ -646,6 +757,108 @@
"tab.mode(dropna=False)"
]
},
{
"cell_type": "markdown",
"id": "b248fef1",
"metadata": {},
"source": [
"### Table.sem()\n",
"\n",
"```\n",
"Table.sem(axis=0, skipna=True, numeric_only=False, ddof=0)\n",
"```\n",
"Return unbiased standard error of the mean over requested axis. Normalized by N-1 by default. This can be changed using the ddof argument\n",
"\n",
"**Parameters:**\n",
"\n",
"| Name | Type | Description | Default |\n",
"| :----------: | :--: | :------------------------------------------------------------------------------- | :-----: |\n",
"| axis | int | The axis to calculate the sum across 0 is columns, 1 is rows. | 0 |\n",
"| skipna | bool | not yet implemented | True |\n",
"| numeric_only | bool | Only use columns of the table that are of a numeric data type. | False |\n",
"| ddof | int | Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N represents the number of elements. | 1 |\n",
"\n",
"**Returns:**\n",
"\n",
"| Type | Description |\n",
"| :----------------: | :------------------------------------------------------------------- |\n",
"| Dictionary | The sem across each row / column with the key corresponding to the row number or column name. |"
]
},
{
"cell_type": "markdown",
"id": "71bd1d6f",
"metadata": {},
"source": [
"**Examples**\n",
"\n",
"Calculate the sem across the columns of a table"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "350c2b7c",
"metadata": {},
"outputs": [],
"source": [
"tab = kx.Table(data=\n",
" {\n",
" 'a': [1, 2, 2, 4],\n",
" 'b': [1, 2, 6, 7],\n",
" 'c': [7, 8, 9, 10],\n",
" 'd': [7, 11, 14, 14],\n",
" }\n",
" )\n",
"tab"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b89307e9",
"metadata": {},
"outputs": [],
"source": [
"tab.sem()"
]
},
{
"cell_type": "markdown",
"id": "6933f01f",
"metadata": {},
"source": [
"Calculate the sem across the rows of a table"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3edd3feb",
"metadata": {},
"outputs": [],
"source": [
"tab.sem(axis=1)"
]
},
{
"cell_type": "markdown",
"id": "ae7afe5a",
"metadata": {},
"source": [
"Calculate sem accross columns with ddof=0:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "de626961",
"metadata": {},
"outputs": [],
"source": [
"tab.sem(ddof=0)"
]
},
{
"cell_type": "markdown",
"id": "7e2813b4",
Expand Down Expand Up @@ -2259,6 +2472,68 @@
"tab.abs(numeric_only=True)"
]
},
{
"cell_type": "markdown",
"id": "0c056fd9-fe7b-43d5-b1c7-7ceec3cae5ff",
"metadata": {},
"source": [
"### Table.round()\n",
"\n",
"```\n",
"Table.round(self, decimals: Union[int, Dict[str, int]] = 0)\n",
"```\n",
"\n",
"Round a Table to a variable number of decimal places.\n",
"\n",
"**Parameters:**\n",
"\n",
"| Name | Type | Description | Default |\n",
"| :--------------: | :-----------------: | :------------------------------------------------------------ | :-----: |\n",
"| decimals | int or Dict | Number of decimal places to round each column to. If an int is given, round each real or float column to the same number of places. Otherwise, dict rounds to variable numbers of places. Column names should be in the keys if decimals parameter is a dict-like and the decimals to round should be the value. Any columns not included in decimals will be left as is. Elements of decimals which are not columns of the input will be ignored.| 0 |\n",
"\n",
"**Returns:**\n",
"\n",
"| Type | Description |\n",
"| :--------: | :--------------------------------------------------------------------------------------- |\n",
"| Table | A Table with the affected columns rounded to the specified number of decimal places. |"
]
},
{
"cell_type": "markdown",
"id": "1b629def",
"metadata": {},
"source": [
"If an integer is provided it rounds every float column to set decimals."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "08c182c9",
"metadata": {},
"outputs": [],
"source": [
"tab.round(1)"
]
},
{
"cell_type": "markdown",
"id": "28853fc0",
"metadata": {},
"source": [
"If a dict whose keys are the column names and its values are the decimals to round set column is provided, it will round them accordingly.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7640df4c",
"metadata": {},
"outputs": [],
"source": [
"tab.round({\"price\": 1, \"traded\": 0})"
]
},
{
"cell_type": "markdown",
"id": "cbcdf84e",
Expand Down Expand Up @@ -2509,7 +2784,48 @@
},
{
"cell_type": "markdown",
"id": "499025cb",
"source": [
"### Table.nunique()\n",
"```\n",
"Table.nunique(axis=0, skipna=True, numeric_only=False, min_count=0)\n",
"```\n",
"\n",
"Returns the number of unique elements across the given axis.\n",
"\n",
"**Parameters:**\n",
"\n",
"| Name | Type | Description | Default |\n",
"| :----------: | :--: |:------------------------------------------------------------------------------------| :-----: |\n",
"| axis | int | The axis to calculate the number of unique elements across 0 is columns, 1 is rows. | 0 |\n",
"| dropna | bool | Don’t include NaN in the counts. | True |\n",
"\n",
"**Returns:**\n",
"\n",
" | Type | Description |\n",
" | :----------------: | :------------------------------------------------------------------- |\n",
" | Dictionary | A dictionary where the key represent the column name / row number and the values are the result of calling `nunique` on that column / row. |"
],
"metadata": {
"collapsed": false
},
"id": "5bc5e813e9673a84"
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"tab.nunique()"
],
"metadata": {
"collapsed": false
},
"id": "f5592b19b69ad46d"
},
{
"cell_type": "markdown",
"id": "655c3ad2",

"metadata": {},
"source": [
"## Setting Indexes"
Expand Down Expand Up @@ -3131,7 +3447,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 5243ca4

Please sign in to comment.