{"id":13989,"date":"2021-06-26T21:22:19","date_gmt":"2021-06-26T15:52:19","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=13989"},"modified":"2021-06-26T21:22:22","modified_gmt":"2021-06-26T15:52:22","slug":"python-lookup-table","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/python-lookup-table\/","title":{"rendered":"Learning About the Python Lookup Table"},"content":{"rendered":"\n<p>The lookup table is used for retrieving values from a database. With lookup tables, we extract data from a database so as to reduce the computations. Retrieving a value from a lookup table is a faster process compared to simple input-output operations. In python, we use dictionaries to perform a lookup table. In this article, we shall be throwing light into different ways of performing a lookup operation in python.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/python-lookup-table\/#Preference_of_lookup_tables\" >Preference of lookup tables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/python-lookup-table\/#Using_Python_Dictionaries\" >Using Python Dictionaries<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/python-lookup-table\/#How_dictionary_uses_a_hash_table_for_python_lookup_table\" >How dictionary uses a hash table for python lookup table<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/python-lookup-table\/#Lookup_function_in_pandas\" >Lookup function in pandas<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/python-lookup-table\/#Syntax_of_the_lookup_function\" >Syntax of the lookup function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/python-lookup-table\/#Return_value\" >Return value:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/python-lookup-table\/#Example_of_Pandas_lookup\" >Example of Pandas lookup()<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/python-lookup-table\/#Using_where_for_lookup\" >Using where() for lookup<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/python-lookup-table\/#Syntax_of_where_function\" >Syntax of where() function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/python-lookup-table\/#Example_of_where\" >Example of where()<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-preference-of-lookup-tables\"><span class=\"ez-toc-section\" id=\"Preference_of_lookup_tables\"><\/span>Preference of lookup tables<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>Lookup tables are used in several programming languages. With lookup tables, we can easily access values from a database. This helps in maintaining <a href=\"http:\/\/www.pythonpool.com\/voluptuous-python\/\" target=\"_blank\" rel=\"noopener\">data integrity in the database system. We can also use lookup tables to validate<\/a> input values in a table. When given a set of input values, with a lookup&nbsp;operation we can retrieve its corresponding output values from the given table or database.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-using-python-dictionaries\"><span class=\"ez-toc-section\" id=\"Using_Python_Dictionaries\"><\/span>Using Python Dictionaries<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Lookup tables are also known as dictionaries in python. Dictionaries represent the implementation of a hash table in order to perform a lookup. Dictionaries consist of key-value pairs. With each key, its corresponding values are accessed. Lookup operations are faster in dictionaries because python implements them using hash tables. We look up the keys in the dictionary and accordingly fetch the key&#8217;s value. <\/p>\n\n\n\n<p>Let us consider a dictionary named <em>&#8216;dictionary&#8217; <\/em>containing key-value pairs. The keys are numerical values, and their values are the number&#8217;s string representation. To fetch the value, we simply lookup using the key.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ndictionary = {0 : 'Zero', 1 : 'One', 2 : 'Two', 3 : 'Three' }\n\nprint(dictionary&#x5B;2])\n<\/pre><\/div>\n\n\n<p><strong>The output is:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Two<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-dictionary-uses-a-hash-table-for-python-lookup-table\"><span class=\"ez-toc-section\" id=\"How_dictionary_uses_a_hash_table_for_python_lookup_table\"><\/span>How dictionary uses a hash table for python lookup table<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Hash tables are a way of implementing dictionaries. Hash tables are the data structures behind dictionaries. In hash tables, we take <span style=\"text-decoration: underline;\"><a href=\"http:\/\/www.pythonpool.com\/python-hashlib\/\" target=\"_blank\" rel=\"noreferrer noopener\">hash<\/a> <\/span>values of a key and apply the hash function to it. Depending on the key, it is mapped to the respective value bucket. Similarly, dictionaries, maps the key values for the lookup operation to their value to retrieve that information. Dictionaries are often called maps because they map the respective key-value to its value. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-lookup-function-in-pandas\"><span class=\"ez-toc-section\" id=\"Lookup_function_in_pandas\"><\/span>Lookup function in pandas<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The pandas library in python contains a <em>lookup() <\/em>function. When given arrays of rows and columns, the<em> lookup()<\/em> function returns an array of values corresponding to each row-column pair. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-syntax-of-the-lookup-function\"><span class=\"ez-toc-section\" id=\"Syntax_of_the_lookup_function\"><\/span>Syntax of the lookup function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>The syntax of the pandas lookup function is:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">DataFrame.lookup(row_labels,&nbsp;col_labels)<\/pre>\n\n\n\n<p>We call the <em>lookup() <\/em>function from the pandas <a href=\"http:\/\/www.pythonpool.com\/numpy-array-to-pandas-dataframe\/\" target=\"_blank\" rel=\"noreferrer noopener\"><span style=\"text-decoration: underline;\">dataframe<\/span><\/a>. <\/p>\n\n\n\n<p><strong>row_labels<\/strong>: It indicates the row labels used for lookup<\/p>\n\n\n\n<p><strong>col_labels<\/strong>: It indicates the column labels used for lookup<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-return-value\"><span class=\"ez-toc-section\" id=\"Return_value\"><\/span>Return value:<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>It returns an n &#8211; dimensional numpy array. <\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-of-pandas-lookup\"><span class=\"ez-toc-section\" id=\"Example_of_Pandas_lookup\"><\/span>Example of Pandas lookup()<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Let us understand the implementation of the <strong><em>lookup()<\/em> <\/strong>function in pandas with the help of an example in python. We shall take a dataframe. First, we shall import the pandas library.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport pandas as pd\n<\/pre><\/div>\n\n\n<p>We shall take a dataframe of six columns and five rows. The dataframe consists of numeric data. After creating the dataframe, we shall print the dataframe.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ndf = pd.DataFrame(&#x5B;&#x5B;3, 15 , 100, 4, 90, 99], &#x5B;0, 30 , 5, 75, 33, 88], &#x5B;2, 16 , 8, 14, 77, 23], &#x5B;1, 116 , 34, 13, 17, 44], &#x5B;4, 25 , 10, 20, 6, 15]], columns=('Index', 0, 1, 2,3,4))\n\nprint(df)\n<\/pre><\/div>\n\n\n<p><strong>The output is:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">   Index    0    1   2   3   4\n0      3   15  100   4  90  99\n1      0   30    5  75  33  88\n2      2   16    8  14  77  23\n3      1  116   34  13  17  44\n4      4   25   10  20   6  15<\/pre>\n\n\n\n<p>Now, we shall use the<em><strong> lookup() function to look for values where the row and column names<\/strong><\/em> are identical. We shall use <em>df.index <\/em>as the dataframe index for the rows and the<em> &#8216;Index&#8217;<\/em> column as the column value. Then, we will save the obtained common values into a new column named <em>&#8216;new&#8217;<\/em>. <\/p>\n\n\n\n<p>For example: When index = 3, the corresponding column value in column 3, which is 90, will be the value in<em> the &#8216;new&#8217;<\/em> column. Similarly, for Index = 0, the corresponding value in column 0, which is 30, will be considered. This shall apply to create the entire<em> &#8216;new&#8217;<\/em> column.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ndf&#x5B;'new'] = df.lookup(df.index, df&#x5B;'Index'])\nprint(df)\n<\/pre><\/div>\n\n\n<p><strong>The output dataframe is:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">   Index    0    1   2   3   4  new\n0      3   15  100   4  90  99   90\n1      0   30    5  75  33  88   30\n2      2   16    8  14  77  23   14\n3      1  116   34  13  17  44   34\n4      4   25   10  20   6  15   15<\/pre>\n\n\n<div class=\"monsterinsights-inline-popular-posts monsterinsights-inline-popular-posts-delta monsterinsights-popular-posts-styled\" ><div class=\"monsterinsights-inline-popular-posts-text\"><span class=\"monsterinsights-inline-popular-posts-icon\" style=\"\"><svg width=\"14\" height=\"19\" viewBox=\"0 0 14 19\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><path d=\"M7.875 0.899463C7.875 1.59183 8.0816 2.24711 8.49479 2.8653C8.93229 3.48349 9.44271 4.06458 10.026 4.60859C10.6337 5.15259 11.2292 5.73369 11.8125 6.35188C12.4201 6.97007 12.9306 7.76135 13.3438 8.72572C13.7812 9.66537 14 10.7163 14 11.8785C14 13.832 13.3073 15.5011 11.9219 16.8858C10.5608 18.2953 8.92014 19 7 19C5.07986 19 3.42708 18.2953 2.04167 16.8858C0.680556 15.5011 0 13.832 0 11.8785C0 9.94973 0.668403 8.28062 2.00521 6.87116C2.27257 6.57443 2.58854 6.50024 2.95312 6.64861C3.31771 6.79697 3.5 7.08134 3.5 7.50171V10.6545C3.5 11.3221 3.71875 11.8908 4.15625 12.3607C4.61806 12.8305 5.16493 13.0654 5.79688 13.0654C6.45312 13.0654 7.01215 12.8428 7.47396 12.3978C7.93576 11.9279 8.16667 11.3592 8.16667 10.6916C8.16667 10.2712 8.04514 9.86318 7.80208 9.46754C7.58333 9.0719 7.31597 8.71336 7 8.3919C6.68403 8.07044 6.34375 7.73662 5.97917 7.39043C5.63889 7.04425 5.34722 6.66097 5.10417 6.2406C4.88542 5.82024 4.73958 5.35041 4.66667 4.83114C4.59375 4.31186 4.67882 3.68131 4.92188 2.93948C5.18924 2.17293 5.63889 1.33219 6.27083 0.417277C6.51389 0.0463641 6.84201 -0.0772735 7.25521 0.0463641C7.6684 0.170002 7.875 0.454368 7.875 0.899463Z\" fill=\"#EB5757\"><\/path><\/svg><\/span><span class=\"monsterinsights-inline-popular-posts-label\" >Trending<\/span><div class=\"monsterinsights-inline-popular-posts-post\"><a class=\"monsterinsights-inline-popular-posts-title\"  href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-cant-compare-datetime-datetime-to-datetime-date\/\">[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date<\/a><\/div><\/div><\/div><p><\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-using-where-for-lookup\"><span class=\"ez-toc-section\" id=\"Using_where_for_lookup\"><\/span>Using where() for lookup<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The numpy library contains a function <em>where().<\/em> The function is used to perform lookup inside a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Database\" target=\"_blank\" rel=\"noreferrer noopener\">database<\/a>. It will check values if they fulfill a certain condition or not. If the condition is fulfilled, then it returns a value<em> &#8216;x&#8217;,<\/em> else, value<em> &#8216;y&#8217;.<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-syntax-of-where-function\"><span class=\"ez-toc-section\" id=\"Syntax_of_where_function\"><\/span>Syntax of where() function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The syntax for <em>where()<\/em> function is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><em>numpy.where(condition[,&nbsp;x,&nbsp;y])<\/em><\/pre>\n\n\n\n<p><strong>condition<\/strong>: It is the condition to be fulfilled. If true, then its value will be<em> &#8216;x&#8217;, <\/em>else its value will be<em> &#8216;y&#8217;.<\/em><\/p>\n\n\n\n<p><strong>x<\/strong>: Value if the condition is True<\/p>\n\n\n\n<p><strong>y<\/strong>: Value if the condition is False<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Return Value:<\/strong><\/p>\n\n\n\n<p><strong>out<\/strong> : It is an n dimensional array containing values<em> &#8216;x&#8217;<\/em> and<em> &#8216;y&#8217; <\/em>depending on the condition.<\/p>\n\n\n<div class=\"monsterinsights-inline-popular-posts monsterinsights-inline-popular-posts-golf monsterinsights-popular-posts-styled\" ><div class=\"monsterinsights-inline-popular-posts-text\"><span class=\"monsterinsights-inline-popular-posts-label\" >Popular now<\/span><span class=\"monsterinsights-inline-popular-posts-border\" ><\/span><span class=\"monsterinsights-inline-popular-posts-border-2\" ><\/span><div class=\"monsterinsights-inline-popular-posts-post\"><a class=\"monsterinsights-inline-popular-posts-title\"  href=\"https:\/\/www.pythonpool.com\/fixed-nameerror-name-unicode-is-not-defined\/\">[Fixed] nameerror: name Unicode is not defined<\/a><\/div><\/div><\/div><p><\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-of-where\"><span class=\"ez-toc-section\" id=\"Example_of_where\"><\/span>Example of where()<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Let us consider a dataframe containing name and age of a person. First, we shall import the numpy and the pandas library.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\nimport pandas as pd\n<\/pre><\/div>\n\n\n<p>Now using Pandas, we will create a dataframe. The dataframe has four records and two columns &#8211; person and age. Then, we shall print the dataframe.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ndf = pd.DataFrame(&#x5B;&#x5B;'Kat', 25 ], &#x5B;'Henry', 16 ], &#x5B;'Liam', 18 ], &#x5B;'Noah', 14 ]], columns=('Person', 'Age'))\n\nprint(df)\n<\/pre><\/div>\n\n\n<p><strong>The output is:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">  Person  Age\n0    Kat   25\n1  Henry   16\n2   Liam   18\n3   Noah   14<\/pre>\n\n\n\n<p><strong>Now, we shall use the <em>np.where() <\/em>function to perform a lookup to check all the people who are eligible for voting. <\/strong><\/p>\n\n\n\n<p>The condition which we will pass inside the where() function is to check if the value of the <em>&#8216;Age&#8217; <\/em>column is greater than or equal to 18 or not. It will only consider those people eligible whose age is greater than or equal to 18. <\/p>\n\n\n\n<p>The function will return<em> &#8216;Eligible&#8217; <\/em>if the condition will be fulfilled. Else it will return<em> &#8216;Not eligible&#8217;. <\/em>Then, we shall store the variable <em>&#8216;x&#8217; <\/em>into a new column inside the dataframe named<em> &#8216;Vote&#8217;.<\/em><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nx = np.where(df&#x5B;'Age']&gt;=18,'Eligible','Not eligible')\ndf&#x5B;'Vote'] = x\nprint(df)\n<\/pre><\/div>\n\n\n<p><strong>The output is:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">  Person  Age          Vote\n0    Kat   25      Eligible\n1  Henry   16  Not eligible\n2   Liam   18      Eligible\n3   Noah   14  Not eligible<\/pre>\n\n\n\n<hr class=\"wp-block-separator is-style-wide\"\/>\n\n\n\n<p>That wraps up the python lookup table. If you have any doubts, let us know in the comments below.<\/p>\n\n\n\n<p><em>Until next time, Keep Learning!<\/em><\/p>\n\n\n<div class=\"monsterinsights-widget-popular-posts monsterinsights-widget-popular-posts-charlie monsterinsights-popular-posts-styled monsterinsights-widget-popular-posts-columns-1\"><ul class=\"monsterinsights-widget-popular-posts-list\"><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-cant-compare-datetime-datetime-to-datetime-date\/\"><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-nameerror-name-unicode-is-not-defined\/\"><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] nameerror: name Unicode is not defined<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/solved-runtimeerror-cuda-error-invalid-device-ordinal\/\"><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Solved] runtimeerror: cuda error: invalid device ordinal<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-type-numpy-ndarray-doesnt-define-__round__-method\/\"><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] typeerror: type numpy.ndarray doesn&#8217;t define __round__ method<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/cannot-mask-with-non-boolean-array-containing-na-nan-values\/\"><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >Cannot mask with non-boolean array containing NA\/NaN values<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-attributeerror-nonetype-object-has-no-attribute-sd_model_hash\/\"><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] attributeerror: nonetype object has no attribute sd_model_hash<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><\/div><\/div><\/a><\/li><\/ul><\/div><p><\/p>","protected":false},"excerpt":{"rendered":"<p>The lookup table is used for retrieving values from a database. With lookup tables, we extract data from a database so as to reduce the &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Learning About the Python Lookup Table\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/python-lookup-table\/#more-13989\" aria-label=\"More on Learning About the Python Lookup Table\">Read more<\/a><\/p>\n","protected":false},"author":20,"featured_media":14053,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15],"tags":[4282,4280,4279,4281,4276,4277,4278],"class_list":["post-13989","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-create-a-lookup-table-in-python","tag-function-lookup-table-python-lambda","tag-lookup-table-python","tag-lookup-table-python-numpy","tag-python-create-lookup-table","tag-python-hash-table-lookup","tag-python-lookup-table-interpolation","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v25.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Learning About the Python Lookup Table - Python Pool<\/title>\n<meta name=\"description\" content=\"Python Lookup table is used for retrieving values from a database so as to reduce the computations by making retrieving data a faster process\" \/>\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.pythonpool.com\/python-lookup-table\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learning About the Python Lookup Table\" \/>\n<meta property=\"og:description\" content=\"The lookup table is used for retrieving values from a database. With lookup tables, we extract data from a database so as to reduce the computations.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/python-lookup-table\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-26T15:52:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-06-26T15:52:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Learning-About-the-Python-Lookup-Table.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1350\" \/>\n\t<meta property=\"og:image:height\" content=\"650\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Dhruvi Vikma\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dhruvi Vikma\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.pythonpool.com\/python-lookup-table\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-lookup-table\/\"},\"author\":{\"name\":\"Dhruvi Vikma\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/bed8fc40c7b71baf7d76b1cfefd79f23\"},\"headline\":\"Learning About the Python Lookup Table\",\"datePublished\":\"2021-06-26T15:52:19+00:00\",\"dateModified\":\"2021-06-26T15:52:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-lookup-table\/\"},\"wordCount\":873,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-lookup-table\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Learning-About-the-Python-Lookup-Table.jpg\",\"keywords\":[\"create a lookup table in python\",\"function lookup table python lambda\",\"lookup table python\",\"lookup table python numpy\",\"python create lookup table\",\"python hash table lookup\",\"python lookup table interpolation\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/python-lookup-table\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pythonpool.com\/python-lookup-table\/\",\"url\":\"https:\/\/www.pythonpool.com\/python-lookup-table\/\",\"name\":\"Learning About the Python Lookup Table - Python Pool\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-lookup-table\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-lookup-table\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Learning-About-the-Python-Lookup-Table.jpg\",\"datePublished\":\"2021-06-26T15:52:19+00:00\",\"dateModified\":\"2021-06-26T15:52:22+00:00\",\"description\":\"Python Lookup table is used for retrieving values from a database so as to reduce the computations by making retrieving data a faster process\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-lookup-table\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/python-lookup-table\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/python-lookup-table\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Learning-About-the-Python-Lookup-Table.jpg\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Learning-About-the-Python-Lookup-Table.jpg\",\"width\":1350,\"height\":650,\"caption\":\"Python Lookup Table\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/python-lookup-table\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Learning About the Python Lookup Table\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/bed8fc40c7b71baf7d76b1cfefd79f23\",\"name\":\"Dhruvi Vikma\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/520d8a37e8b6ce4e6df57e997dc0d571225f48098bbb02838c3884bb603e886f?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/520d8a37e8b6ce4e6df57e997dc0d571225f48098bbb02838c3884bb603e886f?s=96&d=wavatar&r=g\",\"caption\":\"Dhruvi Vikma\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Learning About the Python Lookup Table - Python Pool","description":"Python Lookup table is used for retrieving values from a database so as to reduce the computations by making retrieving data a faster process","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.pythonpool.com\/python-lookup-table\/","og_locale":"en_US","og_type":"article","og_title":"Learning About the Python Lookup Table","og_description":"The lookup table is used for retrieving values from a database. With lookup tables, we extract data from a database so as to reduce the computations.","og_url":"https:\/\/www.pythonpool.com\/python-lookup-table\/","og_site_name":"Python Pool","article_published_time":"2021-06-26T15:52:19+00:00","article_modified_time":"2021-06-26T15:52:22+00:00","og_image":[{"width":1350,"height":650,"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Learning-About-the-Python-Lookup-Table.jpg","type":"image\/jpeg"}],"author":"Dhruvi Vikma","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Dhruvi Vikma","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/python-lookup-table\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/python-lookup-table\/"},"author":{"name":"Dhruvi Vikma","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/bed8fc40c7b71baf7d76b1cfefd79f23"},"headline":"Learning About the Python Lookup Table","datePublished":"2021-06-26T15:52:19+00:00","dateModified":"2021-06-26T15:52:22+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-lookup-table\/"},"wordCount":873,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-lookup-table\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Learning-About-the-Python-Lookup-Table.jpg","keywords":["create a lookup table in python","function lookup table python lambda","lookup table python","lookup table python numpy","python create lookup table","python hash table lookup","python lookup table interpolation"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/python-lookup-table\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/python-lookup-table\/","url":"https:\/\/www.pythonpool.com\/python-lookup-table\/","name":"Learning About the Python Lookup Table - Python Pool","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-lookup-table\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-lookup-table\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Learning-About-the-Python-Lookup-Table.jpg","datePublished":"2021-06-26T15:52:19+00:00","dateModified":"2021-06-26T15:52:22+00:00","description":"Python Lookup table is used for retrieving values from a database so as to reduce the computations by making retrieving data a faster process","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/python-lookup-table\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/python-lookup-table\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/python-lookup-table\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Learning-About-the-Python-Lookup-Table.jpg","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/06\/Learning-About-the-Python-Lookup-Table.jpg","width":1350,"height":650,"caption":"Python Lookup Table"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/python-lookup-table\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Learning About the Python Lookup Table"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/bed8fc40c7b71baf7d76b1cfefd79f23","name":"Dhruvi Vikma","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/520d8a37e8b6ce4e6df57e997dc0d571225f48098bbb02838c3884bb603e886f?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/520d8a37e8b6ce4e6df57e997dc0d571225f48098bbb02838c3884bb603e886f?s=96&d=wavatar&r=g","caption":"Dhruvi Vikma"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/13989","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=13989"}],"version-history":[{"count":31,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/13989\/revisions"}],"predecessor-version":[{"id":24527,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/13989\/revisions\/24527"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/14053"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=13989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=13989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=13989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}