From 8fa87c07d327582190d7006b0144b4fcddec4364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20V=C3=A1zquez?= Date: Wed, 29 Nov 2023 12:01:35 +0100 Subject: [PATCH 1/5] add_prefix function and add_sufix function implementations --- docs/user-guide/advanced/Pandas_API.ipynb | 615 ++++++++++++---------- src/pykx/pandas_api/pandas_indexing.py | 54 +- tests/test_pandas_api.py | 41 ++ 3 files changed, 440 insertions(+), 270 deletions(-) diff --git a/docs/user-guide/advanced/Pandas_API.ipynb b/docs/user-guide/advanced/Pandas_API.ipynb index 239c4c8..cef8121 100644 --- a/docs/user-guide/advanced/Pandas_API.ipynb +++ b/docs/user-guide/advanced/Pandas_API.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "2d0c8656", + "id": "12a1e6cd", "metadata": {}, "source": [ "# Pandas API\n", @@ -23,7 +23,7 @@ { "cell_type": "code", "execution_count": null, - "id": "17f28b87", + "id": "2f4437ca", "metadata": {}, "outputs": [], "source": [ @@ -38,7 +38,7 @@ }, { "cell_type": "markdown", - "id": "774122a0", + "id": "13e03cb2", "metadata": {}, "source": [ "## Constructing Tables" @@ -46,7 +46,7 @@ }, { "cell_type": "markdown", - "id": "0fd8910c", + "id": "e76d1fc5", "metadata": {}, "source": [ "### Table\n", @@ -75,7 +75,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9a748c27", + "id": "7b5f69f2", "metadata": {}, "outputs": [], "source": [ @@ -84,7 +84,7 @@ }, { "cell_type": "markdown", - "id": "231a5e28", + "id": "673d9e9a", "metadata": {}, "source": [ "Create a Table from an array like object." @@ -93,7 +93,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7e43d716", + "id": "c701c1b9", "metadata": {}, "outputs": [], "source": [ @@ -102,7 +102,7 @@ }, { "cell_type": "markdown", - "id": "1e426cda", + "id": "c8eb1622", "metadata": {}, "source": [ "Create a Table from an array like object and provide names for the columns to use." @@ -111,7 +111,7 @@ { "cell_type": "code", "execution_count": null, - "id": "2b3c2edf", + "id": "103f866d", "metadata": {}, "outputs": [], "source": [ @@ -120,7 +120,7 @@ }, { "cell_type": "markdown", - "id": "be094191", + "id": "bfd1da8e", "metadata": {}, "source": [ "### Keyed Table\n", @@ -150,7 +150,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d93e73d3", + "id": "765be7de", "metadata": {}, "outputs": [], "source": [ @@ -159,7 +159,7 @@ }, { "cell_type": "markdown", - "id": "119c2e1f", + "id": "f8082a5a", "metadata": {}, "source": [ "Create a keyed table from a list of rows." @@ -168,7 +168,7 @@ { "cell_type": "code", "execution_count": null, - "id": "959fcd3d", + "id": "ecd10819", "metadata": {}, "outputs": [], "source": [ @@ -177,7 +177,7 @@ }, { "cell_type": "markdown", - "id": "9d83854e", + "id": "7be93c23", "metadata": {}, "source": [ "Create a keyed table from a list of rows and provide names for the resulting columns." @@ -186,7 +186,7 @@ { "cell_type": "code", "execution_count": null, - "id": "4b2c6989", + "id": "51d94e4d", "metadata": {}, "outputs": [], "source": [ @@ -195,7 +195,7 @@ }, { "cell_type": "markdown", - "id": "356b29d8", + "id": "8157961c", "metadata": {}, "source": [ "Create a keyed table with a specified index column." @@ -204,7 +204,7 @@ { "cell_type": "code", "execution_count": null, - "id": "acbe339c", + "id": "2405a759", "metadata": {}, "outputs": [], "source": [ @@ -213,7 +213,7 @@ }, { "cell_type": "markdown", - "id": "95a04686", + "id": "e9ff8aa6", "metadata": {}, "source": [ "## Metadata" @@ -222,7 +222,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a52fdc82", + "id": "fed3a938", "metadata": {}, "outputs": [], "source": [ @@ -233,7 +233,7 @@ }, { "cell_type": "markdown", - "id": "280baf05", + "id": "3e5de382", "metadata": {}, "source": [ "### Table.columns\n", @@ -244,7 +244,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a2ee3fad", + "id": "a355d654", "metadata": {}, "outputs": [], "source": [ @@ -253,7 +253,7 @@ }, { "cell_type": "markdown", - "id": "40da029e", + "id": "9baab247", "metadata": {}, "source": [ "### Table.dtypes\n", @@ -264,7 +264,7 @@ { "cell_type": "code", "execution_count": null, - "id": "70bd32d2", + "id": "f72c7071", "metadata": {}, "outputs": [], "source": [ @@ -273,7 +273,7 @@ }, { "cell_type": "markdown", - "id": "00e49e84", + "id": "5393cbb5", "metadata": {}, "source": [ "### Table.empty\n", @@ -284,7 +284,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9dc49e08", + "id": "d62ce629", "metadata": {}, "outputs": [], "source": [ @@ -293,7 +293,7 @@ }, { "cell_type": "markdown", - "id": "c00e46ef", + "id": "de0a60d6", "metadata": {}, "source": [ "### Table.ndim\n", @@ -304,7 +304,7 @@ { "cell_type": "code", "execution_count": null, - "id": "db113636", + "id": "27aa4a92", "metadata": {}, "outputs": [], "source": [ @@ -313,7 +313,7 @@ }, { "cell_type": "markdown", - "id": "5ea4b315", + "id": "d8b6533c", "metadata": {}, "source": [ "### Table.shape\n", @@ -324,7 +324,7 @@ { "cell_type": "code", "execution_count": null, - "id": "78125654", + "id": "3bd69cae", "metadata": {}, "outputs": [], "source": [ @@ -333,7 +333,7 @@ }, { "cell_type": "markdown", - "id": "1e3f85a5", + "id": "50f7c03c", "metadata": {}, "source": [ "### Table.size\n", @@ -344,7 +344,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c77c5bc7", + "id": "072269ec", "metadata": { "scrolled": false }, @@ -355,7 +355,7 @@ }, { "cell_type": "markdown", - "id": "2be2ece3", + "id": "394b9b9d", "metadata": {}, "source": [ "### Table.mean()\n", @@ -382,7 +382,7 @@ }, { "cell_type": "markdown", - "id": "cb8c5ef8", + "id": "7d0ae9ce", "metadata": {}, "source": [ "**Examples:**\n", @@ -393,7 +393,7 @@ { "cell_type": "code", "execution_count": null, - "id": "0c3e5d76", + "id": "0a3883ab", "metadata": {}, "outputs": [], "source": [ @@ -411,7 +411,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9986a550", + "id": "65f9d7ed", "metadata": {}, "outputs": [], "source": [ @@ -420,7 +420,7 @@ }, { "cell_type": "markdown", - "id": "24ac0b99", + "id": "94f312a5", "metadata": {}, "source": [ "Calculate the mean across the rows of a table" @@ -429,7 +429,7 @@ { "cell_type": "code", "execution_count": null, - "id": "41f6f669", + "id": "3d96dc12", "metadata": {}, "outputs": [], "source": [ @@ -438,7 +438,7 @@ }, { "cell_type": "markdown", - "id": "7bf853c5", + "id": "d102ec1b", "metadata": {}, "source": [ "### Table.median()\n", @@ -465,7 +465,7 @@ }, { "cell_type": "markdown", - "id": "98da458a", + "id": "e2341a7c", "metadata": {}, "source": [ "**Examples:**\n", @@ -476,7 +476,7 @@ { "cell_type": "code", "execution_count": null, - "id": "bff5ac07", + "id": "d9a17a3b", "metadata": {}, "outputs": [], "source": [ @@ -494,7 +494,7 @@ { "cell_type": "code", "execution_count": null, - "id": "579c8b33", + "id": "d93621d4", "metadata": {}, "outputs": [], "source": [ @@ -503,7 +503,7 @@ }, { "cell_type": "markdown", - "id": "f6698350", + "id": "b9822d60", "metadata": {}, "source": [ "Calculate the median across the rows of a table" @@ -512,7 +512,7 @@ { "cell_type": "code", "execution_count": null, - "id": "5664bd93", + "id": "ab0b5159", "metadata": { "scrolled": false }, @@ -523,7 +523,7 @@ }, { "cell_type": "markdown", - "id": "33af56bb", + "id": "7041b59d", "metadata": {}, "source": [ "### Table.mode()\n", @@ -551,7 +551,7 @@ }, { "cell_type": "markdown", - "id": "4201c9af", + "id": "100d30fa", "metadata": {}, "source": [ "**Examples:**\n", @@ -562,7 +562,7 @@ { "cell_type": "code", "execution_count": null, - "id": "b4bfe36c", + "id": "806786d9", "metadata": {}, "outputs": [], "source": [ @@ -580,7 +580,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e1a7eeb1", + "id": "7ccc77a8", "metadata": { "scrolled": true }, @@ -591,7 +591,7 @@ }, { "cell_type": "markdown", - "id": "6a47af49", + "id": "3bf74453", "metadata": {}, "source": [ "Calculate the median across the rows of a table" @@ -600,7 +600,7 @@ { "cell_type": "code", "execution_count": null, - "id": "130081ce", + "id": "d3c86b05", "metadata": { "scrolled": false }, @@ -611,7 +611,7 @@ }, { "cell_type": "markdown", - "id": "29dffe0d", + "id": "ab19909d", "metadata": {}, "source": [ "Calculate the mode across columns and keep null values." @@ -620,7 +620,7 @@ { "cell_type": "code", "execution_count": null, - "id": "53a8251a", + "id": "cf30480e", "metadata": { "scrolled": true }, @@ -639,7 +639,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f8558148", + "id": "f5e48708", "metadata": {}, "outputs": [], "source": [ @@ -648,7 +648,7 @@ }, { "cell_type": "markdown", - "id": "7e2813b4", + "id": "24cf11d3", "metadata": {}, "source": [ "## Indexing" @@ -657,7 +657,7 @@ { "cell_type": "code", "execution_count": null, - "id": "77ab64ab", + "id": "6fb377dc", "metadata": {}, "outputs": [], "source": [ @@ -669,7 +669,7 @@ }, { "cell_type": "markdown", - "id": "69313988", + "id": "c1c04832", "metadata": {}, "source": [ "### Table.head()\n", @@ -695,7 +695,7 @@ }, { "cell_type": "markdown", - "id": "edf33458", + "id": "3a1376fd", "metadata": {}, "source": [ "**Examples:**\n", @@ -706,7 +706,7 @@ { "cell_type": "code", "execution_count": null, - "id": "916fcf4d", + "id": "f0bf8f86", "metadata": { "scrolled": false }, @@ -717,7 +717,7 @@ }, { "cell_type": "markdown", - "id": "cb58279a", + "id": "93e184ff", "metadata": {}, "source": [ "Return the first 10 rows of the table." @@ -726,7 +726,7 @@ { "cell_type": "code", "execution_count": null, - "id": "bf32db40", + "id": "9e3e5b67", "metadata": {}, "outputs": [], "source": [ @@ -735,7 +735,7 @@ }, { "cell_type": "markdown", - "id": "a5c4a5e9", + "id": "76e7a8fe", "metadata": {}, "source": [ "### Table.tail()\n", @@ -761,7 +761,7 @@ }, { "cell_type": "markdown", - "id": "4e3fee46", + "id": "bc99337e", "metadata": {}, "source": [ "**Examples:**\n", @@ -772,7 +772,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a0d34e0b", + "id": "3b261b98", "metadata": {}, "outputs": [], "source": [ @@ -781,7 +781,7 @@ }, { "cell_type": "markdown", - "id": "e223e705", + "id": "9871118a", "metadata": {}, "source": [ "Return the last 10 rows of the table." @@ -790,7 +790,7 @@ { "cell_type": "code", "execution_count": null, - "id": "4edae0c3", + "id": "dd3970b3", "metadata": {}, "outputs": [], "source": [ @@ -799,7 +799,7 @@ }, { "cell_type": "markdown", - "id": "c87325f8", + "id": "507b8049", "metadata": {}, "source": [ "### Table.get()\n", @@ -826,7 +826,7 @@ }, { "cell_type": "markdown", - "id": "7c96cd34", + "id": "ec0f77c7", "metadata": {}, "source": [ "**Examples:**\n", @@ -837,7 +837,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7f64d914", + "id": "5a5a6d38", "metadata": { "scrolled": true }, @@ -848,7 +848,7 @@ }, { "cell_type": "markdown", - "id": "88ee5698", + "id": "528ef898", "metadata": {}, "source": [ "Get the `y` and `z` columns from the table." @@ -857,7 +857,7 @@ { "cell_type": "code", "execution_count": null, - "id": "daef6ce6", + "id": "50dc3d41", "metadata": { "scrolled": true }, @@ -868,7 +868,7 @@ }, { "cell_type": "markdown", - "id": "26a53f6d", + "id": "5671306b", "metadata": {}, "source": [ "Attempt to get the `q` column from the table and recieve none as that column does not exist." @@ -877,7 +877,7 @@ { "cell_type": "code", "execution_count": null, - "id": "3856084d", + "id": "f4e793d7", "metadata": {}, "outputs": [], "source": [ @@ -886,7 +886,7 @@ }, { "cell_type": "markdown", - "id": "91932d32", + "id": "4ae7804e", "metadata": {}, "source": [ "Attempt to get the `q` column from the table and recieve the default value `not found` as that column does not exist." @@ -895,7 +895,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7d2a2bcf", + "id": "4fb7dafd", "metadata": {}, "outputs": [], "source": [ @@ -904,7 +904,7 @@ }, { "cell_type": "markdown", - "id": "9e831e14", + "id": "b9bffb97", "metadata": {}, "source": [ "### Table.at[]\n", @@ -922,7 +922,7 @@ }, { "cell_type": "markdown", - "id": "97519657", + "id": "631f538b", "metadata": {}, "source": [ "**Examples:**\n", @@ -933,7 +933,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9cd275bf", + "id": "e88eb0b9", "metadata": {}, "outputs": [], "source": [ @@ -942,7 +942,7 @@ }, { "cell_type": "markdown", - "id": "1fd39083", + "id": "3b2a6f91", "metadata": {}, "source": [ "Reassign the value of the `z` column in the 997th row to `3.14159`." @@ -951,7 +951,7 @@ { "cell_type": "code", "execution_count": null, - "id": "814fa8e0", + "id": "514ceeb0", "metadata": {}, "outputs": [], "source": [ @@ -961,7 +961,7 @@ }, { "cell_type": "markdown", - "id": "7815e8c3", + "id": "9d807946", "metadata": {}, "source": [ "### Table.loc[]\n", @@ -997,7 +997,7 @@ }, { "cell_type": "markdown", - "id": "5ee06186", + "id": "fc696884", "metadata": {}, "source": [ "**Examples:**\n", @@ -1008,7 +1008,7 @@ { "cell_type": "code", "execution_count": null, - "id": "12fc6807", + "id": "076e08a4", "metadata": { "scrolled": true }, @@ -1019,7 +1019,7 @@ }, { "cell_type": "markdown", - "id": "97206dd7", + "id": "dd6c4a2f", "metadata": {}, "source": [ "Get all rows of the table where the value in the `z` column is greater than `250.0`" @@ -1028,7 +1028,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a6c9add0", + "id": "eec5938e", "metadata": {}, "outputs": [], "source": [ @@ -1037,7 +1037,7 @@ }, { "cell_type": "markdown", - "id": "a32aca6b", + "id": "8ce7195e", "metadata": {}, "source": [ "Replace all null values in the column `v` with the value `-100`." @@ -1046,7 +1046,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c1ad3a23", + "id": "4fec8625", "metadata": { "scrolled": true }, @@ -1058,7 +1058,7 @@ }, { "cell_type": "markdown", - "id": "447b9fd2", + "id": "81343ea4", "metadata": {}, "source": [ "Replace all locations in column `v` where the value is `-100` with a null." @@ -1067,7 +1067,7 @@ { "cell_type": "code", "execution_count": null, - "id": "31ea02c9", + "id": "d49ba7ff", "metadata": {}, "outputs": [], "source": [ @@ -1077,7 +1077,7 @@ }, { "cell_type": "markdown", - "id": "ac4c5e4b", + "id": "dirty-deviation", "metadata": {}, "source": [ "Usage of the `loc` functionality under the hood additionally allows users to set columns within a table for single or multiple columns. Data passed for this can be q/Python." @@ -1086,7 +1086,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f378ba4a", + "id": "economic-administration", "metadata": {}, "outputs": [], "source": [ @@ -1096,7 +1096,7 @@ { "cell_type": "code", "execution_count": null, - "id": "0f2936b9", + "id": "parliamentary-simon", "metadata": {}, "outputs": [], "source": [ @@ -1105,7 +1105,7 @@ }, { "cell_type": "markdown", - "id": "a3368987", + "id": "8aeb5b10", "metadata": {}, "source": [ "### Table.iloc[]\n", @@ -1135,7 +1135,7 @@ }, { "cell_type": "markdown", - "id": "0ef4d8cf", + "id": "a6e24ecf", "metadata": {}, "source": [ "**Examples:**\n", @@ -1146,7 +1146,7 @@ { "cell_type": "code", "execution_count": null, - "id": "683ab48b", + "id": "a3460c85", "metadata": { "scrolled": true }, @@ -1157,7 +1157,7 @@ }, { "cell_type": "markdown", - "id": "e71bebdb", + "id": "2bdb5d71", "metadata": {}, "source": [ "Get the first 5 rows from a table." @@ -1166,7 +1166,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a13730fd", + "id": "4ef3767c", "metadata": { "scrolled": false }, @@ -1177,7 +1177,7 @@ }, { "cell_type": "markdown", - "id": "60f892e0", + "id": "f869425e", "metadata": {}, "source": [ "Get all rows of the table where the `y` column is equal to `AAPL`." @@ -1186,7 +1186,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d7afdf65", + "id": "bd3d1613", "metadata": { "scrolled": true }, @@ -1197,7 +1197,7 @@ }, { "cell_type": "markdown", - "id": "8b3b9279", + "id": "bcc638af", "metadata": {}, "source": [ "Get all rows of the table where the `y` column is equal to `AAPL`, and only return the `y`, `z` and `w` columns." @@ -1206,7 +1206,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a0d9f08d", + "id": "19491b1a", "metadata": {}, "outputs": [], "source": [ @@ -1215,7 +1215,7 @@ }, { "cell_type": "markdown", - "id": "045bc156", + "id": "7a7bcdd8", "metadata": {}, "source": [ "Replace all null values in the column `v` with the value `-100`." @@ -1224,7 +1224,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7e21c163", + "id": "8dbd832b", "metadata": {}, "outputs": [], "source": [ @@ -1234,7 +1234,7 @@ }, { "cell_type": "markdown", - "id": "76021266", + "id": "37ad1ee6", "metadata": {}, "source": [ "### Table.pop()\n", @@ -1260,7 +1260,7 @@ }, { "cell_type": "markdown", - "id": "e5fdfbd3", + "id": "a7e8dc98", "metadata": {}, "source": [ "**Examples:**\n", @@ -1271,7 +1271,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7a960191", + "id": "cc748ad8", "metadata": { "scrolled": true }, @@ -1286,7 +1286,7 @@ }, { "cell_type": "markdown", - "id": "35062560", + "id": "231ebfbb", "metadata": {}, "source": [ "Remove the `z` and `w` columns from the table and return them." @@ -1295,7 +1295,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a46189b2", + "id": "2aea8b3e", "metadata": { "scrolled": false }, @@ -1310,7 +1310,7 @@ }, { "cell_type": "markdown", - "id": "f71b6917", + "id": "56ce1b1d", "metadata": {}, "source": [ "## Reindexing" @@ -1319,7 +1319,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a2b1a198", + "id": "a4c1d74b", "metadata": { "scrolled": true }, @@ -1333,7 +1333,7 @@ }, { "cell_type": "markdown", - "id": "f5a7ac0e", + "id": "e47a4340", "metadata": {}, "source": [ "### Table.drop()\n", @@ -1360,7 +1360,7 @@ }, { "cell_type": "markdown", - "id": "008a2e74", + "id": "a0417a0f", "metadata": {}, "source": [ "**Examples:**\n", @@ -1371,7 +1371,7 @@ { "cell_type": "code", "execution_count": null, - "id": "0f74d3f2", + "id": "2932fb5f", "metadata": {}, "outputs": [], "source": [ @@ -1380,7 +1380,7 @@ }, { "cell_type": "markdown", - "id": "cb4e82aa", + "id": "5368f9f1", "metadata": {}, "source": [ "Drop columns from a table." @@ -1389,7 +1389,7 @@ { "cell_type": "code", "execution_count": null, - "id": "57ad6a64", + "id": "02c1221f", "metadata": {}, "outputs": [], "source": [ @@ -1398,7 +1398,7 @@ }, { "cell_type": "markdown", - "id": "90db87b0", + "id": "a88ea856", "metadata": {}, "source": [ "### Table.drop_duplicates()\n", @@ -1418,7 +1418,7 @@ }, { "cell_type": "markdown", - "id": "3af33f03", + "id": "90493dae", "metadata": {}, "source": [ "**Examples:**\n", @@ -1429,7 +1429,7 @@ { "cell_type": "code", "execution_count": null, - "id": "af182307", + "id": "baccc6bd", "metadata": {}, "outputs": [], "source": [ @@ -1439,7 +1439,7 @@ }, { "cell_type": "markdown", - "id": "48143d51", + "id": "cd94c2b6", "metadata": {}, "source": [ "Drop all duplicate rows from the table." @@ -1448,7 +1448,7 @@ { "cell_type": "code", "execution_count": null, - "id": "eeff16e7", + "id": "c6dfca99", "metadata": {}, "outputs": [], "source": [ @@ -1457,7 +1457,7 @@ }, { "cell_type": "markdown", - "id": "6d71c8c0", + "id": "ece21d55", "metadata": {}, "source": [ "### Table.rename()\n", @@ -1483,7 +1483,7 @@ }, { "cell_type": "markdown", - "id": "73260da1", + "id": "d49a17ce", "metadata": {}, "source": [ "**Examples:**\n", @@ -1494,7 +1494,7 @@ { "cell_type": "code", "execution_count": null, - "id": "3cc68fa6", + "id": "585ea2e9", "metadata": {}, "outputs": [], "source": [ @@ -1503,7 +1503,7 @@ }, { "cell_type": "markdown", - "id": "eef94948", + "id": "b88b46fd", "metadata": {}, "source": [ "Rename column `y` to `symbol` and `z` to `price`." @@ -1512,7 +1512,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d5e76248", + "id": "ed9c511f", "metadata": {}, "outputs": [], "source": [ @@ -1521,7 +1521,127 @@ }, { "cell_type": "markdown", - "id": "05124590", + "metadata": {}, + "source": [ + "### Table.add_prefix()\n", + "\n", + "```\n", + "Table.add_prefix(columns)\n", + "```\n", + "\n", + "Rename columns adding a prefix in a table and return the resulting Table object.\n", + "\n", + "**Parameters:**\n", + "\n", + "| Name | Type | Description | Default |\n", + "| :-----: | :-------------: | :------------------------------------------------------------------ | :--------: |\n", + "| prefix | str | The string that will be concatenated with the name of the columns | _required_ |\n", + "| axis | int | Axis to add prefix on. | 0 |\n", + "\n", + "**Returns:**\n", + "\n", + "| Type | Description |\n", + "| :---: | :----------------------------------------------------------------- |\n", + "| Table | A table with the given column(s) renamed adding a prefix. |" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Examples:**\n", + "\n", + "he initial table to which a prefix will be added to its columns" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "tab.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Add \"col_\" to table columns:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "tab.add_prefix(prefix=\"col_\").head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Table.add_suffix()\n", + "\n", + "```\n", + "Table.add_sufix(suffix, axis)\n", + "```\n", + "\n", + "Rename columns adding a suffix in a table and return the resulting Table object.\n", + "\n", + "**Parameters:**\n", + "\n", + "| Name | Type | Description | Default |\n", + "| :-----: | :-------------: | :------------------------------------------------------------------ | :--------: |\n", + "| suffix | str | The string that will be concatenated with the name of the columns | _required_ |\n", + "| axis | int | Axis to add suffix on. | 0 |\n", + "\n", + "**Returns:**\n", + "\n", + "| Type | Description |\n", + "| :---: | :----------------------------------------------------------------- |\n", + "| Table | A table with the given column(s) renamed adding a suffix. |" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Examples:**\n", + "\n", + "The initial table to which a suffix will be added to its columns" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "tab.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Add \"_col\" to table columns:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "tab.add_suffix(prefix=\"_col\").head()" + ] + }, + { + "cell_type": "markdown", + "id": "10582eaa", "metadata": {}, "source": [ "### Table.sample()\n", @@ -1553,7 +1673,7 @@ }, { "cell_type": "markdown", - "id": "e8f78917", + "id": "0271484d", "metadata": {}, "source": [ "**Examples:**\n", @@ -1564,7 +1684,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d88ab348", + "id": "187059eb", "metadata": {}, "outputs": [], "source": [ @@ -1573,7 +1693,7 @@ }, { "cell_type": "markdown", - "id": "78e03554", + "id": "d5d52b8b", "metadata": {}, "source": [ "Sample 10% of the rows." @@ -1582,7 +1702,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8585d62e", + "id": "f6aa2289", "metadata": {}, "outputs": [], "source": [ @@ -1591,7 +1711,7 @@ }, { "cell_type": "markdown", - "id": "c77712d3", + "id": "a9d80fe9", "metadata": {}, "source": [ "Sample 10% of the rows and allow the same row to be sampled twice." @@ -1600,7 +1720,7 @@ { "cell_type": "code", "execution_count": null, - "id": "b138f770", + "id": "17096534", "metadata": {}, "outputs": [], "source": [ @@ -1609,7 +1729,7 @@ }, { "cell_type": "markdown", - "id": "6f6f5672", + "id": "32794d29", "metadata": {}, "source": [ "### Table.select_dtypes()\n", @@ -1638,7 +1758,7 @@ }, { "cell_type": "markdown", - "id": "6a703c57", + "id": "a94cc6e5", "metadata": {}, "source": [ "**Examples:**\n", @@ -1649,7 +1769,7 @@ { "cell_type": "code", "execution_count": null, - "id": "5e9734f7", + "id": "8fcaa4fb", "metadata": {}, "outputs": [], "source": [ @@ -1658,7 +1778,7 @@ }, { "cell_type": "markdown", - "id": "42d9ffa6", + "id": "3dc6ef75", "metadata": {}, "source": [ "Exclude columns contatining symbols" @@ -1667,7 +1787,7 @@ { "cell_type": "code", "execution_count": null, - "id": "3d934cf0", + "id": "7d1a3e61", "metadata": {}, "outputs": [], "source": [ @@ -1676,7 +1796,7 @@ }, { "cell_type": "markdown", - "id": "e4302f7d", + "id": "7009cb76", "metadata": {}, "source": [ "Include a list of column types" @@ -1685,7 +1805,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f698f5f0", + "id": "b71e87fa", "metadata": {}, "outputs": [], "source": [ @@ -1694,7 +1814,7 @@ }, { "cell_type": "markdown", - "id": "5590d1ca", + "id": "54417754", "metadata": {}, "source": [ "### Table.astype()\n", @@ -1723,7 +1843,7 @@ }, { "cell_type": "markdown", - "id": "f9ca98d2", + "id": "20546f87", "metadata": {}, "source": [ "**Examples:**\n", @@ -1734,7 +1854,7 @@ { "cell_type": "code", "execution_count": null, - "id": "831836c8", + "id": "33e3cf56", "metadata": {}, "outputs": [], "source": [ @@ -1743,7 +1863,7 @@ }, { "cell_type": "markdown", - "id": "0bf0d78f", + "id": "16b2ee25", "metadata": {}, "source": [ "Cast all columns to dtype LongVector" @@ -1752,7 +1872,7 @@ { "cell_type": "code", "execution_count": null, - "id": "6833400a", + "id": "ac977798", "metadata": {}, "outputs": [], "source": [ @@ -1761,7 +1881,7 @@ }, { "cell_type": "markdown", - "id": "7a2bfcd3", + "id": "51850e87", "metadata": {}, "source": [ "Casting as specified in the dcitionary supplied with given dtype per column" @@ -1770,7 +1890,7 @@ { "cell_type": "code", "execution_count": null, - "id": "872db9aa", + "id": "d8c2f1f9", "metadata": {}, "outputs": [], "source": [ @@ -1779,7 +1899,7 @@ }, { "cell_type": "markdown", - "id": "ef3b4225", + "id": "ada1bfd4", "metadata": {}, "source": [ "The next example will use this table" @@ -1788,7 +1908,7 @@ { "cell_type": "code", "execution_count": null, - "id": "6a20abdd", + "id": "ab8261b8", "metadata": {}, "outputs": [], "source": [ @@ -1797,7 +1917,7 @@ }, { "cell_type": "markdown", - "id": "908fa4ea", + "id": "a2972dc0", "metadata": {}, "source": [ "Casting char and string columns to symbol columns" @@ -1806,7 +1926,7 @@ { "cell_type": "code", "execution_count": null, - "id": "5ea7fe9e", + "id": "c2c019bc", "metadata": {}, "outputs": [], "source": [ @@ -1815,7 +1935,7 @@ }, { "cell_type": "markdown", - "id": "718584f8", + "id": "e0b57863", "metadata": {}, "source": [ "## Merging" @@ -1823,7 +1943,7 @@ }, { "cell_type": "markdown", - "id": "ef401426", + "id": "8b1c0dc5", "metadata": {}, "source": [ "### Table.merge()\n", @@ -1875,7 +1995,7 @@ }, { "cell_type": "markdown", - "id": "9e613e3c", + "id": "9542857c", "metadata": {}, "source": [ "**Examples:**\n", @@ -1886,7 +2006,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a3b0ec9f", + "id": "847941a9", "metadata": { "scrolled": true }, @@ -1899,7 +2019,7 @@ }, { "cell_type": "markdown", - "id": "6e32596c", + "id": "4b6793c9", "metadata": {}, "source": [ "Merge tab1 and tab2 on the lkey and rkey columns using a native q inner join. The value columns have the default suffixes, \\_x and \\_y, appended." @@ -1908,7 +2028,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8ea253c9", + "id": "023b555b", "metadata": {}, "outputs": [], "source": [ @@ -1917,7 +2037,7 @@ }, { "cell_type": "markdown", - "id": "2d9240b3", + "id": "9449f90b", "metadata": {}, "source": [ "Merge tab1 and tab2 with specified left and right suffixes appended to any overlapping columns." @@ -1926,7 +2046,7 @@ { "cell_type": "code", "execution_count": null, - "id": "64425a1d", + "id": "87ad643d", "metadata": {}, "outputs": [], "source": [ @@ -1935,7 +2055,7 @@ }, { "cell_type": "markdown", - "id": "e749c7e0", + "id": "49deadfd", "metadata": {}, "source": [ "Merge tab1 and tab2 but raise an exception if the Tables have any overlapping columns." @@ -1944,7 +2064,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a938230d", + "id": "a3d45ec4", "metadata": { "scrolled": true }, @@ -1959,7 +2079,7 @@ { "cell_type": "code", "execution_count": null, - "id": "b1d99a31", + "id": "ee3ef9a8", "metadata": {}, "outputs": [], "source": [ @@ -1969,7 +2089,7 @@ }, { "cell_type": "markdown", - "id": "385c0465", + "id": "b62f2e3b", "metadata": {}, "source": [ "Merge tab1 and tab2 on the `a` column using an inner join." @@ -1978,7 +2098,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7431a148", + "id": "8f17070f", "metadata": { "scrolled": true }, @@ -1989,7 +2109,7 @@ }, { "cell_type": "markdown", - "id": "230a7666", + "id": "2aaf6b4b", "metadata": {}, "source": [ "Merge tab1 and tab2 on the `a` column using a left join." @@ -1998,7 +2118,7 @@ { "cell_type": "code", "execution_count": null, - "id": "04b96b08", + "id": "64cfb314", "metadata": {}, "outputs": [], "source": [ @@ -2007,7 +2127,7 @@ }, { "cell_type": "markdown", - "id": "d991656c", + "id": "374c2905", "metadata": {}, "source": [ "Merge tab1 and tab2 using a cross join." @@ -2016,7 +2136,7 @@ { "cell_type": "code", "execution_count": null, - "id": "09886503", + "id": "51f94109", "metadata": { "scrolled": true }, @@ -2029,7 +2149,7 @@ }, { "cell_type": "markdown", - "id": "b2f4aff1", + "id": "d4293b88", "metadata": {}, "source": [ "### Table.merge_asof()\n", @@ -2086,7 +2206,7 @@ }, { "cell_type": "markdown", - "id": "fc696ccf", + "id": "bf6bc139", "metadata": {}, "source": [ "**Examples:**\n", @@ -2097,7 +2217,7 @@ { "cell_type": "code", "execution_count": null, - "id": "6cb634e0", + "id": "338f553c", "metadata": {}, "outputs": [], "source": [ @@ -2109,7 +2229,7 @@ { "cell_type": "code", "execution_count": null, - "id": "81b10932", + "id": "2d7b0d9b", "metadata": {}, "outputs": [], "source": [ @@ -2119,7 +2239,7 @@ { "cell_type": "code", "execution_count": null, - "id": "411d19d2", + "id": "5949e8b3", "metadata": {}, "outputs": [], "source": [ @@ -2128,7 +2248,7 @@ }, { "cell_type": "markdown", - "id": "324d24ec", + "id": "6976cfc0", "metadata": {}, "source": [ "Perform a asof join on two tables but first merge them on the by column." @@ -2137,7 +2257,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d805fa5c", + "id": "7e9c7ee0", "metadata": {}, "outputs": [], "source": [ @@ -2183,7 +2303,7 @@ { "cell_type": "code", "execution_count": null, - "id": "665d0e74", + "id": "444c426a", "metadata": {}, "outputs": [], "source": [ @@ -2193,7 +2313,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9398ab6a", + "id": "d2e16d4a", "metadata": {}, "outputs": [], "source": [ @@ -2202,7 +2322,7 @@ }, { "cell_type": "markdown", - "id": "acca5289", + "id": "ca5c9a5f", "metadata": {}, "source": [ "## Computations" @@ -2211,7 +2331,7 @@ { "cell_type": "code", "execution_count": null, - "id": "852b5f34", + "id": "674cb468", "metadata": {}, "outputs": [], "source": [ @@ -2223,7 +2343,7 @@ }, { "cell_type": "markdown", - "id": "93a50ee2", + "id": "92136283", "metadata": {}, "source": [ "### Table.abs()\n", @@ -2250,7 +2370,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7da5d72b", + "id": "7b08d857", "metadata": { "scrolled": true }, @@ -2261,7 +2381,7 @@ }, { "cell_type": "markdown", - "id": "cbcdf84e", + "id": "ad57d9cf", "metadata": {}, "source": [ "### Table.all()\n", @@ -2290,7 +2410,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7d0b0cd3", + "id": "b37d2e15", "metadata": {}, "outputs": [], "source": [ @@ -2299,7 +2419,7 @@ }, { "cell_type": "markdown", - "id": "aa02cf1c", + "id": "fd14012f", "metadata": {}, "source": [ "### Table.any()\n", @@ -2328,7 +2448,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a4806993", + "id": "581cf133", "metadata": {}, "outputs": [], "source": [ @@ -2337,7 +2457,7 @@ }, { "cell_type": "markdown", - "id": "a3c3fccd", + "id": "c42f7ec0", "metadata": {}, "source": [ "### Table.max()\n", @@ -2366,7 +2486,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8e9abf02", + "id": "dd8a84e1", "metadata": {}, "outputs": [], "source": [ @@ -2375,7 +2495,7 @@ }, { "cell_type": "markdown", - "id": "301ab2c2", + "id": "fb28288f", "metadata": {}, "source": [ "### Table.min()\n", @@ -2404,7 +2524,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c1255ac7", + "id": "0fe40c65", "metadata": {}, "outputs": [], "source": [ @@ -2413,7 +2533,7 @@ }, { "cell_type": "markdown", - "id": "a389f7aa", + "id": "af783468", "metadata": {}, "source": [ "### Table.sum()\n", @@ -2443,7 +2563,7 @@ { "cell_type": "code", "execution_count": null, - "id": "af638f53", + "id": "32519605", "metadata": {}, "outputs": [], "source": [ @@ -2452,7 +2572,7 @@ }, { "cell_type": "markdown", - "id": "9bf62b1a", + "id": "621766f6", "metadata": {}, "source": [ "### Table.prod()\n", @@ -2482,7 +2602,7 @@ { "cell_type": "code", "execution_count": null, - "id": "0ddad367", + "id": "97c7c26b", "metadata": { "scrolled": true }, @@ -2500,7 +2620,7 @@ { "cell_type": "code", "execution_count": null, - "id": "151411e2", + "id": "9222c8ba", "metadata": {}, "outputs": [], "source": [ @@ -2509,7 +2629,7 @@ }, { "cell_type": "markdown", - "id": "499025cb", + "id": "655c3ad2", "metadata": {}, "source": [ "## Setting Indexes" @@ -2517,7 +2637,7 @@ }, { "cell_type": "markdown", - "id": "4dc576e8", + "id": "6ad74ce0", "metadata": {}, "source": [ "### Table.set_index()\n", @@ -2558,7 +2678,7 @@ { "cell_type": "code", "execution_count": null, - "id": "42a288f7", + "id": "bdd21889", "metadata": {}, "outputs": [], "source": [ @@ -2569,7 +2689,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f744959e", + "id": "cf782f61", "metadata": {}, "outputs": [], "source": [ @@ -2580,7 +2700,7 @@ { "cell_type": "code", "execution_count": null, - "id": "00c31275", + "id": "0c54f760", "metadata": {}, "outputs": [], "source": [ @@ -2591,7 +2711,7 @@ { "cell_type": "code", "execution_count": null, - "id": "858bbeb2", + "id": "825afd87", "metadata": {}, "outputs": [], "source": [ @@ -2602,7 +2722,7 @@ }, { "cell_type": "markdown", - "id": "450c30ee", + "id": "72efa53c", "metadata": {}, "source": [ "Appending:" @@ -2611,7 +2731,7 @@ { "cell_type": "code", "execution_count": null, - "id": "b475c811", + "id": "d2b9b266", "metadata": {}, "outputs": [], "source": [ @@ -2622,7 +2742,7 @@ { "cell_type": "code", "execution_count": null, - "id": "0fb2c59c", + "id": "af569818", "metadata": {}, "outputs": [], "source": [ @@ -2632,7 +2752,7 @@ }, { "cell_type": "markdown", - "id": "887ffb99", + "id": "3224889a", "metadata": {}, "source": [ "Verify Integrity:" @@ -2641,7 +2761,7 @@ { "cell_type": "code", "execution_count": null, - "id": "49367c46", + "id": "74347bef", "metadata": {}, "outputs": [], "source": [ @@ -2652,7 +2772,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7bb2aaf0", + "id": "edca3507", "metadata": {}, "outputs": [], "source": [ @@ -2665,7 +2785,7 @@ }, { "cell_type": "markdown", - "id": "7e415861", + "id": "e9d74bb5", "metadata": {}, "source": [ "## Group By" @@ -2673,7 +2793,7 @@ }, { "cell_type": "markdown", - "id": "8b2d72fb", + "id": "ae3ec2eb", "metadata": {}, "source": [ "### Table.groupby()\n", @@ -2724,7 +2844,7 @@ { "cell_type": "code", "execution_count": null, - "id": "0789d3f4", + "id": "189eabbe", "metadata": { "scrolled": true }, @@ -2741,7 +2861,7 @@ }, { "cell_type": "markdown", - "id": "8baae3c9", + "id": "d805052d", "metadata": {}, "source": [ "Group on the `Animal` column and calculate the mean of the resulting `Max Speed` and `Max Altitude` columns." @@ -2750,7 +2870,7 @@ { "cell_type": "code", "execution_count": null, - "id": "734cb6ff", + "id": "00cc7660", "metadata": { "scrolled": true }, @@ -2761,7 +2881,7 @@ }, { "cell_type": "markdown", - "id": "b3b759af", + "id": "c7ef160d", "metadata": {}, "source": [ "Example table with multiple columns to group on." @@ -2770,7 +2890,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7966c28c", + "id": "3204bd59", "metadata": {}, "outputs": [], "source": [ @@ -2786,7 +2906,7 @@ }, { "cell_type": "markdown", - "id": "e3ab5b1f", + "id": "77008f71", "metadata": {}, "source": [ "Group on multiple columns using thier indexes." @@ -2795,7 +2915,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c01d3cc9", + "id": "cfd22d01", "metadata": {}, "outputs": [], "source": [ @@ -2804,7 +2924,7 @@ }, { "cell_type": "markdown", - "id": "d46304f0", + "id": "58e77d29", "metadata": {}, "source": [ "Example table with Nulls." @@ -2813,7 +2933,7 @@ { "cell_type": "code", "execution_count": null, - "id": "dc222240", + "id": "96bb6e4d", "metadata": {}, "outputs": [], "source": [ @@ -2831,7 +2951,7 @@ }, { "cell_type": "markdown", - "id": "4c38e902", + "id": "a13c11f4", "metadata": {}, "source": [ "Group on column `a` and keep null groups." @@ -2840,7 +2960,7 @@ { "cell_type": "code", "execution_count": null, - "id": "833e4a92", + "id": "95d7734a", "metadata": { "scrolled": true }, @@ -2851,7 +2971,7 @@ }, { "cell_type": "markdown", - "id": "c26a98ff", + "id": "1645ae2b", "metadata": {}, "source": [ "Group on column `a` keeping null groups and not using the groups as an index column." @@ -2860,7 +2980,7 @@ { "cell_type": "code", "execution_count": null, - "id": "bb5d1bac", + "id": "bf8dc14c", "metadata": {}, "outputs": [], "source": [ @@ -2869,7 +2989,7 @@ }, { "cell_type": "markdown", - "id": "af8fad39", + "id": "undefined-bruce", "metadata": {}, "source": [ "## Apply\n", @@ -2917,7 +3037,7 @@ { "cell_type": "code", "execution_count": null, - "id": "02f41281", + "id": "cooperative-construction", "metadata": {}, "outputs": [], "source": [ @@ -2928,7 +3048,7 @@ }, { "cell_type": "markdown", - "id": "cf555661", + "id": "micro-dodge", "metadata": {}, "source": [ "Apply square root on each item within a column" @@ -2937,7 +3057,7 @@ { "cell_type": "code", "execution_count": null, - "id": "173acc13", + "id": "handmade-bridal", "metadata": {}, "outputs": [], "source": [ @@ -2946,7 +3066,7 @@ }, { "cell_type": "markdown", - "id": "a00dda0c", + "id": "accepted-planning", "metadata": {}, "source": [ "Apply a reducing function sum on either axis" @@ -2955,7 +3075,7 @@ { "cell_type": "code", "execution_count": null, - "id": "4936ea30", + "id": "acquired-wholesale", "metadata": {}, "outputs": [], "source": [ @@ -2965,60 +3085,17 @@ { "cell_type": "code", "execution_count": null, - "id": "5df4a3ac", + "id": "informal-algebra", "metadata": {}, "outputs": [], "source": [ "tab.apply(lambda x: sum(x), axis=1)" ] - }, - { - "cell_type": "markdown", - "id": "8da6da7c", - "metadata": {}, - "source": [ - "## Aggregate\n", - "\n", - "### Table.agg()\n", - "\n", - "```\n", - "Table.agg(\n", - " func,\n", - " axis=0,\n", - " *args,\n", - " **kwargs\n", - ")\n", - "```\n", - "\n", - "Aggregate data using one or more operations over a specified axis\n", - "\n", - "Objects passed to a function are passed as kx vector/list objects.\n", - "\n", - "**Parameters:**\n", - "\n", - "| Name | Type | Description | Default |\n", - "| :--------------: | :---------------------------------: | :-------------------------------------------------------------------------- | :------: |\n", - "| func | function, str, list or dict | Function to use for aggregating the data. If a function this must either work when passed a `Table` or when passed to `Table.apply`

Accepted combinations are: