{"id":199100,"date":"2023-11-20T10:04:40","date_gmt":"2023-11-20T15:04:40","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=199100"},"modified":"2023-11-20T10:05:11","modified_gmt":"2023-11-20T15:05:11","slug":"employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\/","title":{"rendered":"Employing Human Order in pandas DataFrame Sorting: Risk Factors and Tenors"},"content":{"rendered":"\n<p><em>The post &#8220;Employing Human Order in pandas DataFrame Sorting: Risk Factors and Tenors&#8221; first appeared on <a href=\"https:\/\/quantatrisk.com\/2019\/12\/02\/human-order-pandas-dataframe-sorting\/\">Quant at Risk<\/a> blog.<\/em><\/p>\n\n\n\n<p>There are various Python projects which require sorting but not the ones that employ a default alphanumeric functionality. We talk about manually specified order or&nbsp;<em>human-order<\/em>, in short. One of such examples is the case study presented below.<\/p>\n\n\n\n<p>Imagine that your risk system provides you with a list of various risk factors and the corresponding risk tenors. The latter may differ among risk factors and your task is to quickly convert an input data row into a matrix of tenor-series assuming that all your tenors follow a human-order defined as:<\/p>\n\n\n\n<p class=\"has-text-align-center\">1W, 2W, 3W, 1M, 2M, 3M, \u2026, 11M, 1Y, 2Y, 3Y, \u2026, 49Y, 50Y<\/p>\n\n\n\n<p>Let\u2019s analyse an exemplary input dataset:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Employing Human-Order in pandas DataFrame Sorting: Risk Factors and Tenors\n# (c) 2019 by QuantAtRisk.com\n \nimport numpy as np\nimport pandas as pd\n \ndata = pd.read_csv('Libo3.csv', header=0)\ndisplay(data)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"674\" height=\"469\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/quant-at-risk-dataframe-sorting-chart.png\" alt=\"\" class=\"wp-image-199105 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/quant-at-risk-dataframe-sorting-chart.png 674w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/quant-at-risk-dataframe-sorting-chart-300x209.png 300w\" data-sizes=\"(max-width: 674px) 100vw, 674px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 674px; aspect-ratio: 674\/469;\" \/><\/figure>\n\n\n\n<p>The trouble with standard sorting order is that usually it will end up with 10Y placed before 1Y or week-tenors (W) will follow monthly tenors since M appears before W, and\u2026 we don\u2019t want the outcome to be that way. We can see that if we attempt to perform:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">for risk_factor in data.Risk_Factor.unique():\n    print(risk_factor)\n    lst = data[data.Risk_Factor == risk_factor].Tenor.tolist()\n    print(sorted(lst))\n    print()<\/pre>\n\n\n\n<p>Libo3.GBP.ON.SWAP<br>[&#8217;10M&#8217;, &#8216;1M&#8217;, &#8216;1W&#8217;, &#8216;2Y&#8217;, &#8217;30Y&#8217;, &#8216;3W&#8217;, &#8216;5M&#8217;, &#8216;7M&#8217;]<\/p>\n\n\n\n<p>Libo3.EUR.ON.SWAP<br>[&#8217;10M&#8217;, &#8216;1M&#8217;, &#8216;1W&#8217;, &#8217;21Y&#8217;, &#8217;30Y&#8217;, &#8216;3W&#8217;, &#8216;4M&#8217;, &#8216;7M&#8217;]<\/p>\n\n\n\n<p><strong>Solution<\/strong><\/p>\n\n\n\n<p>First we need to specify a human-order sorting key:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ho = ['ON']  # overnight\nho.extend([str(i) + 'W' for i in range(1,4)])  # weekly tenors\nho.extend([str(i) + 'M' for i in range(1,12)])  # monthly tenors\nho.extend([str(i) + 'Y' for i in range(1,51)])  # yearly tenors<\/pre>\n\n\n\n<p>what will store:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">print(ho)<\/pre>\n\n\n\n<p>[&#8216;ON&#8217;, &#8216;1W&#8217;, &#8216;2W&#8217;, &#8216;3W&#8217;, &#8216;1M&#8217;, &#8216;2M&#8217;, &#8216;3M&#8217;, &#8216;4M&#8217;, &#8216;5M&#8217;, &#8216;6M&#8217;, &#8216;7M&#8217;, &#8216;8M&#8217;, &#8216;9M&#8217;, &#8217;10M&#8217;,<br>&#8217;11M&#8217;, &#8216;1Y&#8217;, &#8216;2Y&#8217;, &#8216;3Y&#8217;, &#8216;4Y&#8217;, &#8216;5Y&#8217;, &#8216;6Y&#8217;, &#8216;7Y&#8217;, &#8216;8Y&#8217;, &#8216;9Y&#8217;, &#8217;10Y&#8217;, &#8217;11Y&#8217;, &#8217;12Y&#8217;,<br>&#8217;13Y&#8217;, &#8217;14Y&#8217;, &#8217;15Y&#8217;, &#8217;16Y&#8217;, &#8217;17Y&#8217;, &#8217;18Y&#8217;, &#8217;19Y&#8217;, &#8217;20Y&#8217;, &#8217;21Y&#8217;, &#8217;22Y&#8217;, &#8217;23Y&#8217;, &#8217;24Y&#8217;,<br>&#8217;25Y&#8217;, &#8217;26Y&#8217;, &#8217;27Y&#8217;, &#8217;28Y&#8217;, &#8217;29Y&#8217;, &#8217;30Y&#8217;, &#8217;31Y&#8217;, &#8217;32Y&#8217;, &#8217;33Y&#8217;, &#8217;34Y&#8217;, &#8217;35Y&#8217;, &#8217;36Y&#8217;,<br>&#8217;37Y&#8217;, &#8217;38Y&#8217;, &#8217;39Y&#8217;, &#8217;40Y&#8217;, &#8217;41Y&#8217;, &#8217;42Y&#8217;, &#8217;43Y&#8217;, &#8217;44Y&#8217;, &#8217;45Y&#8217;, &#8217;46Y&#8217;, &#8217;47Y&#8217;, &#8217;48Y&#8217;,<br>&#8217;49Y&#8217;, &#8217;50Y&#8217;]<\/p>\n\n\n\n<p>Next, we need to set&nbsp;<em>Tenor<\/em>s as \u201ccategory\u201d type (line #23-24) and sort values according to requested order (line #25). Have a look:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">data.Tenor = data.Tenor.astype('category')\ndata.Tenor.cat.set_categories(ho, inplace=True)\ndata = data.sort_values([\"Risk_Factor\", \"Tenor\"])\ndata.reset_index(inplace=True, drop=True)\n \ndisplay(data)  # let's inspect the result<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"642\" height=\"488\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/quant-at-risk-dataframe-sorting-chart-2.png\" alt=\"\" class=\"wp-image-199107 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/quant-at-risk-dataframe-sorting-chart-2.png 642w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/quant-at-risk-dataframe-sorting-chart-2-300x228.png 300w\" data-sizes=\"(max-width: 642px) 100vw, 642px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 642px; aspect-ratio: 642\/488;\" \/><\/figure>\n\n\n\n<p>That accomplishes our task. From now on, you can manipulate the data in any way, for example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">fi = True  # first iteration\n \nfor risk_factor in data.Risk_Factor.unique():\n    tmp = data[data.Risk_Factor == risk_factor]\n    tmp.set_index('Tenor', drop=True, inplace=True)\n    tmp = tmp.rename(columns={tmp.columns[1] : risk_factor})\n    del tmp[tmp.columns[0]]\n    if fi:\n        df = tmp\n        fi = False\n    else:\n        df = df.join(tmp, how='outer', sort=True)  # applying 'sort' keyword\n                                                   # here preserves a correct \n                                                   # human-order\ndisplay(df)<\/pre>\n\n\n\n<p>will allow you for every risk factor to join the data using all available&nbsp;<em>Tenor<\/em>s set as a common index:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"651\" height=\"308\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/quant-at-risk-dataframe-sorting-chart-3.png\" alt=\"\" class=\"wp-image-199109 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/quant-at-risk-dataframe-sorting-chart-3.png 651w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/quant-at-risk-dataframe-sorting-chart-3-300x142.png 300w\" data-sizes=\"(max-width: 651px) 100vw, 651px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 651px; aspect-ratio: 651\/308;\" \/><\/figure>\n\n\n\n<p><em>Disclaimer: The input data were randomly generated.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Imagine that your risk system provides you with a list of various risk factors and the corresponding risk tenors. <\/p>\n","protected":false},"author":710,"featured_media":36684,"comment_status":"open","ping_status":"closed","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,343,349,338,341],"tags":[806,4922,1225,1224,595],"contributors-categories":[13732],"class_list":{"0":"post-199100","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science","8":"category-programing-languages","9":"category-python-development","10":"category-ibkr-quant-news","11":"category-quant-development","12":"tag-data-science","13":"tag-econometrics","14":"tag-numpy","15":"tag-pandas","16":"tag-python","17":"contributors-categories-quant-at-risk"},"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Employing Human Order in pandas DataFrame Sorting: Risk Factors and Tenors<\/title>\n<meta name=\"description\" content=\"Imagine that your risk system provides you with a list of various risk factors and the corresponding risk tenors.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/199100\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Employing Human Order in pandas DataFrame Sorting: Risk Factors and Tenors | IBKR Campus US\" \/>\n<meta property=\"og:description\" content=\"Imagine that your risk system provides you with a list of various risk factors and the corresponding risk tenors.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-20T15:04:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-20T15:05:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/02\/digits-numbers-tech.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"900\" \/>\n\t<meta property=\"og:image:height\" content=\"540\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Dr. Pawel Lachowicz\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr. Pawel Lachowicz\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Dr. Pawel Lachowicz\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/5097d856a095fc59920af69437fb1797\"\n\t            },\n\t            \"headline\": \"Employing Human Order in pandas DataFrame Sorting: Risk Factors and Tenors\",\n\t            \"datePublished\": \"2023-11-20T15:04:40+00:00\",\n\t            \"dateModified\": \"2023-11-20T15:05:11+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\\\/\"\n\t            },\n\t            \"wordCount\": 361,\n\t            \"commentCount\": 0,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/02\\\/digits-numbers-tech.jpg\",\n\t            \"keywords\": [\n\t                \"Data Science\",\n\t                \"Econometrics\",\n\t                \"NumPy\",\n\t                \"Pandas\",\n\t                \"Python\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Programming Languages\",\n\t                \"Python Development\",\n\t                \"Quant\",\n\t                \"Quant Development\"\n\t            ],\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"CommentAction\",\n\t                    \"name\": \"Comment\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\\\/#respond\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\\\/\",\n\t            \"name\": \"Employing Human Order in pandas DataFrame Sorting: Risk Factors and Tenors | IBKR Campus US\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/02\\\/digits-numbers-tech.jpg\",\n\t            \"datePublished\": \"2023-11-20T15:04:40+00:00\",\n\t            \"dateModified\": \"2023-11-20T15:05:11+00:00\",\n\t            \"description\": \"Imagine that your risk system provides you with a list of various risk factors and the corresponding risk tenors.\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/02\\\/digits-numbers-tech.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/02\\\/digits-numbers-tech.jpg\",\n\t            \"width\": 900,\n\t            \"height\": 540,\n\t            \"caption\": \"Quant\"\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/5097d856a095fc59920af69437fb1797\",\n\t            \"name\": \"Dr. Pawel Lachowicz\",\n\t            \"sameAs\": [\n\t                \"https:\\\/\\\/quantatrisk.com\\\/\"\n\t            ],\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/pawellachowicz\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Employing Human Order in pandas DataFrame Sorting: Risk Factors and Tenors","description":"Imagine that your risk system provides you with a list of various risk factors and the corresponding risk tenors.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/199100\/","og_locale":"en_US","og_type":"article","og_title":"Employing Human Order in pandas DataFrame Sorting: Risk Factors and Tenors | IBKR Campus US","og_description":"Imagine that your risk system provides you with a list of various risk factors and the corresponding risk tenors.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\/","og_site_name":"IBKR Campus US","article_published_time":"2023-11-20T15:04:40+00:00","article_modified_time":"2023-11-20T15:05:11+00:00","og_image":[{"width":900,"height":540,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/02\/digits-numbers-tech.jpg","type":"image\/jpeg"}],"author":"Dr. Pawel Lachowicz","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Dr. Pawel Lachowicz","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\/"},"author":{"name":"Dr. Pawel Lachowicz","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/5097d856a095fc59920af69437fb1797"},"headline":"Employing Human Order in pandas DataFrame Sorting: Risk Factors and Tenors","datePublished":"2023-11-20T15:04:40+00:00","dateModified":"2023-11-20T15:05:11+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\/"},"wordCount":361,"commentCount":0,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/02\/digits-numbers-tech.jpg","keywords":["Data Science","Econometrics","NumPy","Pandas","Python"],"articleSection":["Data Science","Programming Languages","Python Development","Quant","Quant Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\/","name":"Employing Human Order in pandas DataFrame Sorting: Risk Factors and Tenors | IBKR Campus US","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/02\/digits-numbers-tech.jpg","datePublished":"2023-11-20T15:04:40+00:00","dateModified":"2023-11-20T15:05:11+00:00","description":"Imagine that your risk system provides you with a list of various risk factors and the corresponding risk tenors.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/employing-human-order-in-pandas-dataframe-sorting-risk-factors-and-tenors\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/02\/digits-numbers-tech.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/02\/digits-numbers-tech.jpg","width":900,"height":540,"caption":"Quant"},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/5097d856a095fc59920af69437fb1797","name":"Dr. Pawel Lachowicz","sameAs":["https:\/\/quantatrisk.com\/"],"url":"https:\/\/www.interactivebrokers.com\/campus\/author\/pawellachowicz\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/02\/digits-numbers-tech.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/199100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/710"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=199100"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/199100\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/36684"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=199100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=199100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=199100"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=199100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}