{
"cells": [
{
"cell_type": "markdown",
"id": "bbee10b5-c5e1-4dbe-aeb1-f5289372e89e",
"metadata": {},
"source": [
"# pandasの高速化"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "7adf116d-5898-4a7b-b292-25a9ad65208c",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"from pandarallel import pandarallel\n",
"import swifter"
]
},
{
"cell_type": "markdown",
"id": "e32d3a36-a97e-4b72-b470-2725181b3641",
"metadata": {},
"source": [
"ここではorderbookのデータをDataFrameに読み込みます。"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "36b5fd1f-463e-43f0-8212-265f9efeb3b6",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" price | \n",
" size | \n",
" timestamp | \n",
" side | \n",
"
\n",
" \n",
" \n",
" \n",
" 2020-07-08 22:00:05 | \n",
" 9433.24 | \n",
" 2.305583 | \n",
" 2020-07-08 22:00:05 | \n",
" bid | \n",
"
\n",
" \n",
" 2020-07-08 22:00:05 | \n",
" 9434.32 | \n",
" 1.000000 | \n",
" 2020-07-08 22:00:05 | \n",
" ask | \n",
"
\n",
" \n",
" 2020-07-08 22:00:05 | \n",
" 9434.35 | \n",
" 0.530100 | \n",
" 2020-07-08 22:00:05 | \n",
" ask | \n",
"
\n",
" \n",
" 2020-07-08 22:00:05 | \n",
" 9434.90 | \n",
" 0.015848 | \n",
" 2020-07-08 22:00:05 | \n",
" ask | \n",
"
\n",
" \n",
" 2020-07-08 22:00:05 | \n",
" 9435.00 | \n",
" 0.050000 | \n",
" 2020-07-08 22:00:05 | \n",
" ask | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" price size timestamp side\n",
"2020-07-08 22:00:05 9433.24 2.305583 2020-07-08 22:00:05 bid\n",
"2020-07-08 22:00:05 9434.32 1.000000 2020-07-08 22:00:05 ask\n",
"2020-07-08 22:00:05 9434.35 0.530100 2020-07-08 22:00:05 ask\n",
"2020-07-08 22:00:05 9434.90 0.015848 2020-07-08 22:00:05 ask\n",
"2020-07-08 22:00:05 9435.00 0.050000 2020-07-08 22:00:05 ask"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"raw_df = pd.read_pickle(\"btcusd_2020-07-08.pickle\")\n",
"raw_df.head()"
]
},
{
"cell_type": "markdown",
"id": "bd1441dc-bf62-452a-8b9d-215452886725",
"metadata": {},
"source": [
"depth=10の板情報からbid/askが最も近い価格(price)と枚数(size)を抽出します。"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "62585f89-eae2-4f88-b35b-c500e6d8f12c",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" bid_price | \n",
" bid_size | \n",
" ask_price | \n",
" ask_size | \n",
"
\n",
" \n",
" \n",
" \n",
" 2020-07-08 22:00:05 | \n",
" 9433.24 | \n",
" 2.305583 | \n",
" 9433.25 | \n",
" 0.015848 | \n",
"
\n",
" \n",
" 2020-07-08 22:00:06 | \n",
" 9433.24 | \n",
" 2.305583 | \n",
" 9433.25 | \n",
" 0.015848 | \n",
"
\n",
" \n",
" 2020-07-08 22:00:07 | \n",
" 9433.24 | \n",
" 2.323611 | \n",
" 9433.25 | \n",
" 0.015848 | \n",
"
\n",
" \n",
" 2020-07-08 22:00:08 | \n",
" 9433.61 | \n",
" 1.700000 | \n",
" 9433.62 | \n",
" 0.015848 | \n",
"
\n",
" \n",
" 2020-07-08 22:00:09 | \n",
" 9433.51 | \n",
" 1.650000 | \n",
" 9433.52 | \n",
" 0.015848 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" bid_price bid_size ask_price ask_size\n",
"2020-07-08 22:00:05 9433.24 2.305583 9433.25 0.015848\n",
"2020-07-08 22:00:06 9433.24 2.305583 9433.25 0.015848\n",
"2020-07-08 22:00:07 9433.24 2.323611 9433.25 0.015848\n",
"2020-07-08 22:00:08 9433.61 1.700000 9433.62 0.015848\n",
"2020-07-08 22:00:09 9433.51 1.650000 9433.52 0.015848"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bid = (\n",
" raw_df.groupby(\"side\")\n",
" .get_group(\"bid\")\n",
" .groupby(\"timestamp\")[[\"price\", \"size\"]]\n",
" .max()\n",
")\n",
"ask = (\n",
" raw_df.groupby(\"side\")\n",
" .get_group(\"ask\")\n",
" .groupby(\"timestamp\")[[\"price\", \"size\"]]\n",
" .min()\n",
")\n",
"df = pd.concat([bid, ask], axis=1)\n",
"df.index.name = None\n",
"df.columns = \"bid_price\", \"bid_size\", \"ask_price\", \"ask_size\"\n",
"df.head()"
]
},
{
"cell_type": "markdown",
"id": "fb123b4b-ad45-41d2-bef1-a2b3524a47c2",
"metadata": {},
"source": [
"サンプルとして、priceとsizeから仲値を算出する関数を作成します。"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "af5b0670-d0c6-40e5-bd7f-84557bc04736",
"metadata": {},
"outputs": [],
"source": [
"def get_mid_price(bid, bid_sz, ask, ask_sz):\n",
" try:\n",
" mid_price = ask + (ask_sz / (ask_sz + bid_sz) * (bid - ask))\n",
" except ZeroDivisionError:\n",
" mid_price = None\n",
" return mid_price\n",
"\n",
"\n",
"def get_mid_price_from_series(ser):\n",
" return get_mid_price(*ser)\n",
"\n",
"\n",
"vfunc = np.vectorize(get_mid_price)"
]
},
{
"cell_type": "markdown",
"id": "b582b179-9561-4c77-b143-ecd28e3c8b97",
"metadata": {},
"source": [
"作成した関数を各行に対して `apply` メソッドで適用します。"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "364947fe-b843-49c5-ac1b-dc8920d572e8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"60.6 ms ± 3.25 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
"source": [
"%timeit df.apply(get_mid_price_from_series, axis=1)"
]
},
{
"cell_type": "markdown",
"id": "ade45794-5bce-41db-85d0-55701c879413",
"metadata": {},
"source": [
"[numpy.vectorize](https://numpy.org/doc/stable/reference/generated/numpy.vectorize.html) はベクトル化した関数を定義します。引数には array-like なオブジェクトを渡します。"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "aca65840-495e-4e51-9ebf-7d7d328e6c5e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.98 ms ± 83.2 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"%timeit vfunc(*df.T.values)"
]
},
{
"cell_type": "markdown",
"id": "1656a1ca-f19a-4cdd-9143-290d4f78f24c",
"metadata": {},
"source": [
"```{tip}\n",
"get_mid_price 関数の処理は関数化をしなくとも、演算子を使った式で算出できます\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "c28235ba-4dc1-44be-97eb-ec04354bfa7e",
"metadata": {},
"outputs": [],
"source": [
"bid_, bid_sz_, ask_, ask_sz_ = df.T.values"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "7ac9e478-9388-444d-8e5f-497477d74f3c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"22.8 µs ± 440 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)\n"
]
}
],
"source": [
"%timeit ask_ + (ask_sz_ / (ask_sz_ + bid_sz_) * (bid_ - ask_))"
]
},
{
"cell_type": "markdown",
"id": "23a1f037-5e58-49d4-855a-8c3978d57e34",
"metadata": {},
"source": [
"```{tip}\n",
"get_mid_price 関数内の処理は配列(numpy.ndarray)に対応しているため、この関数の引数にSeriesなどを渡せます\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "419d7973-ae1e-4920-92d0-70dcbbe6ec94",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"120 µs ± 7.4 µs per loop (mean ± std. dev. of 7 runs, 10,000 loops each)\n"
]
}
],
"source": [
"%timeit get_mid_price(*df.T.values)"
]
},
{
"cell_type": "markdown",
"id": "58fd4c32-1378-4571-a7dc-57d722905b33",
"metadata": {},
"source": [
"- [Pandaral·lel](https://github.com/nalepae/pandarallel)\n",
"- [swifter](https://github.com/jmcarpenter2/swifter)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "0f379ded-690c-4ab3-a818-26399817be24",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"INFO: Pandarallel will run on 4 workers.\n",
"INFO: Pandarallel will use Memory file system to transfer data between the main process and workers.\n"
]
}
],
"source": [
"pandarallel.initialize()"
]
},
{
"cell_type": "markdown",
"id": "ab51949d-03b1-4c41-8bb4-ebe9354877cd",
"metadata": {},
"source": [
"DataFrameから `apply` メソッドの代わりに `parallel_apply` メソッドを実行すると、関数を並列に適用します。"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "4fea4994-6b46-4e78-affe-e4b9464c89bf",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"83 ms ± 3.21 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
"source": [
"%timeit df.parallel_apply(get_mid_price_from_series, axis=1)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "d2889fe3-26e0-4cdf-a2d9-3dc32a8fcb14",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3ba3da8d5415441ea93efc873f3f36ea",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9b2c4405d93e448d8975c3046185ddb9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a6bba536b0594c9cb085a86edb21a874",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "456807a94eb14c6e9388b8e9fb57e44b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b497aa94754040ee82f9121b283c2172",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8419c05981244bfcb419ebc580004d41",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f19229d1ac7e4373b352e86d79187819",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d83c7046119942f985ede8bd3387af77",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ff0dfd0f8b6e4eb5890b8faa70fff501",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8330fdcfa32b488fac14da5a759489da",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ec4e111b3d014d8291078cafe17e036a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1557a6a92e5e43ce9b9d2ab7c5affcfa",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "797e2bc91b8e41739c1c72eb59d97a49",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ad4fea97c230441c9efb55c1f10ca53a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "22b49010984241c4952127bf8104f1a2",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a0ffe5ec48f349fe9ba27d9b41c6a1c5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9d549f327f43410689e9bf43a2f08ea8",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2d45ad0a4cd445d0ae5a27c3242f2951",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "56843b6422fb4dc89c6c3e28a0a7fb05",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "361c9978b86d471b9d571ac9839ad94e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0ad5193c738f4c4abb9f17b48f938b32",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "617e8430d64f4fec8f5731386ef3b009",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ef75d278d3a545f080aa6a8674a5c5ad",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d8dfe6ef324e4e2ba2ba7a135202a65a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "816bb288b7454fc9bb77ea6c9380dc6d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "90524ea214ca4a7caf74b2edf77e0f63",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f0e9100e4a3b4494a82df5b1e3685f20",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0f37bc2d68dc4429a2a264653e6db3cd",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "fa35ecf063f4414abc1a2bdf3819a233",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "795284ffd1a04f8b9e6f542a0ea70ec8",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "dbc97a9c64bb4a0aa6bb0abab13b47e8",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7279c4b7ac4f4635a5c1883b51432b18",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4e117f7e766d40b8b4606d3a686b0010",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "488e29b7036d4b3e95bafde917a6b311",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bcf5afde912d43e9804daab6286acb98",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c29e4a37592d4cc7b5b4ade4a915b509",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "718dd72ed5e7473792b7d7c338a2e590",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "72beebfc3a4947a089b52b0cad3d0278",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7edd8d5438a549a2bf534674b8e62b2a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "db6931041095498db97eb37807770fa8",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7e9bb4f88f1b4ca399f26611de6d34f0",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ff3ac7fd6f984e25855f558fe38492ad",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "839a918488ac421da857f30e71a7e2dc",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "330fdd934bb2495db1ee54209a9a30d9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "50b1a6f56f604a459148f8622ecdf632",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d616b63288f34cfdab38558dc8b9fe91",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f88b44d4969b4f0e9ea14faef855d7ca",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "44bd6888132b40eb9382ec26e5d93c35",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bc10e14317b64bb8b2c61419aca6d0af",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4ea287bc2cf540059419957300e5d0cc",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "782d912865b7444994eb5c553eeb09ab",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5ee8a600a10a44fba628921488bba22f",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d5a6ef3fc6464fb8ac70913beba97261",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "de1bd02473114e0e9462c3a1fdafa925",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "79e12fbde073418ba1b4a7fc058106c8",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b9295d1f5ac64b458634d8a88bf941d8",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "83caf365fda44ce786527adf156895b3",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d692fba79ce44c989a89ab07a4cb8b97",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6de49c7779bf48f2ab6de89ab2e96d2f",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ef2ec53be461470ea1b83a6e84d05946",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9d4674b2b6e5402c9c2fd27287d7ba47",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "72c54acd6ecd4948b6c070eb2723fed6",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "698d02d7e83b4539858e719d058593af",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2d720c6dd9cc4479863564bc167108de",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e5aac70fb616447792b453ce033434cc",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bb20c657042247b6ada76d2b0bc0e552",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "04aaf68130c64884ad60ed45849b904b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "86f08cc8087c4909af7aec0da56ae67e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f0fb922e67df441fa750d5f81fade105",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bd6020d52e6d4435bfe9101487ff9677",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e8f0aed354164cf488f32d90b9800eb1",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "af07d4b542fb41ecb62b2acbbb427835",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3d6842719139414b9147d11b0038778a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "245892a8b1844e9b9d3836dc0adffbdd",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c3860f9dcadb493794e77751d540687a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "228bd41ba3814a5d8400f1b2455d7061",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "73c130b783e54c8da2c12febde5dffad",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ffcffa8750f648b69cc5bbb50cb1ba82",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "eb7792e6358344c1a9c6a3c6821778f1",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5743c106c9094d28ab14fa06203bf38b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ecfc25f9fa6247bd92c1a831ef43c795",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Pandas Apply: 0%| | 0/7068 [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"131 ms ± 10.5 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
"source": [
"%timeit df.swifter.apply(get_mid_price_from_series, axis=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "abffcd26-f7cc-4eb5-82d8-6f4c4d10d967",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}