{"id":6737,"date":"2024-12-17T01:38:49","date_gmt":"2024-12-17T09:38:49","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=6737"},"modified":"2024-12-17T01:43:24","modified_gmt":"2024-12-17T09:43:24","slug":"455-creating-a-simple-table-with-python","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2024\/12\/455-creating-a-simple-table-with-python\/","title":{"rendered":"#455 Creating a Simple Table with Python"},"content":{"rendered":"<p><a href=\"https:\/\/gantovnik.com\/bio-tips\/2024\/12\/455-creating-a-simple-table-with-python\/ex455\/\" rel=\"attachment wp-att-6748\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/12\/ex455.png?resize=233%2C177&#038;ssl=1\" alt=\"\" width=\"233\" height=\"177\" class=\"alignnone size-full wp-image-6748\" srcset=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/12\/ex455.png?w=233&amp;ssl=1 233w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/12\/ex455.png?resize=150%2C114&amp;ssl=1 150w\" sizes=\"(max-width: 233px) 100vw, 233px\" \/><\/a><\/p>\n<pre class=\"lang:python decode:true\">from rich.table import Table\nfrom rich.console import Console\n\nconsole=Console()\ntable = Table(title=\"User Data\")\n\ntable.add_column(\"ID\",justify=\"right\",style=\"cyan\",no_wrap=True)\ntable.add_column(\"Name\",style=\"magenta\")\ntable.add_column(\"Age\",justify=\"right\",style=\"green\")\n\ntable.add_row(\"1\",\"Alice\",\"28\")\ntable.add_row(\"2\",\"Bob\",\"32\")\ntable.add_row(\"3\",\"Charlie\",\"22\")\nconsole.print(table)<\/pre>\n<p>Output:<\/p>\n<pre class=\"lang:python decode:true \">      User Data       \n\u250c\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502 ID \u2502 Name    \u2502 Age \u2502\n\u251c\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502  1 \u2502 Alice   \u2502  28 \u2502\n\u2502  2 \u2502 Bob     \u2502  32 \u2502\n\u2502  3 \u2502 Charlie \u2502  22 \u2502\n\u2514\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2518<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>from rich.table import Table from rich.console import Console console=Console() table = Table(title=&#8221;User Data&#8221;) table.add_column(&#8220;ID&#8221;,justify=&#8221;right&#8221;,style=&#8221;cyan&#8221;,no_wrap=True) table.add_column(&#8220;Name&#8221;,style=&#8221;magenta&#8221;) table.add_column(&#8220;Age&#8221;,justify=&#8221;right&#8221;,style=&#8221;green&#8221;) table.add_row(&#8220;1&#8243;,&#8221;Alice&#8221;,&#8221;28&#8243;) table.add_row(&#8220;2&#8243;,&#8221;Bob&#8221;,&#8221;32&#8243;) table.add_row(&#8220;3&#8243;,&#8221;Charlie&#8221;,&#8221;22&#8243;) console.print(table) Output: User Data \u250c\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2510 \u2502 ID \u2502 Name \u2502 Age \u2502 \u251c\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2524 \u2502 1 \u2502 Alice \u2502 28 \u2502 \u2502 2 \u2502 Bob \u2502 32 \u2502 \u2502 3 \u2502 Charlie \u2502 22 \u2502 \u2514\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2518 &nbsp; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-6737","post","type-post","status-publish","format-standard","hentry","category-python"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-1KF","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1041,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/186-generate-the-feature-importance\/","url_meta":{"origin":6737,"position":0},"title":"#186 Generate the feature importance","author":"gantovnik","date":"2021-11-07","format":false,"excerpt":"","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex186b.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex186b.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex186b.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex186b.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex186b.jpg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":1945,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/386-lineplot-from-a-wide-form-dataset-using-seaborn-library\/","url_meta":{"origin":6737,"position":1},"title":"#386 Lineplot from a wide-form dataset using seaborn library","author":"gantovnik","date":"2023-08-13","format":false,"excerpt":"","rel":"","context":"In &quot;pandas&quot;","block_context":{"text":"pandas","link":"https:\/\/gantovnik.com\/bio-tips\/category\/pandas\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex386.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex386.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex386.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":362,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/clustering-2\/","url_meta":{"origin":6737,"position":2},"title":"#50 Clustering using Python","author":"gantovnik","date":"2019-01-29","format":false,"excerpt":"import os import matplotlib.pyplot as plt import numpy as np from scipy.stats import norm from numpy import array,vstack from scipy.cluster.vq import vq,kmeans #from mpl_toolkits.mplot3d import Axes3D os.chdir(r'D:\\projects\\wordpress\\ex50') os.getcwd() # generate data data=norm.rvs(0,0.3,size=(10000,2)) inside_ball=np.hypot(data[:,0],data[:,1])<1.0 data=data[inside_ball] data = vstack((data, data+array([1,1]),data+array([-1,1]))) #request the data to be separated into three clusters centroids, distortion =\u2026","rel":"","context":"In &quot;machine learning&quot;","block_context":{"text":"machine learning","link":"https:\/\/gantovnik.com\/bio-tips\/category\/machine-learning\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example60.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example60.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example60.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1947,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/387-replot-in-seaborn-library\/","url_meta":{"origin":6737,"position":3},"title":"#387 Replot() in seaborn library","author":"gantovnik","date":"2023-08-13","format":false,"excerpt":"","rel":"","context":"In &quot;plot&quot;","block_context":{"text":"plot","link":"https:\/\/gantovnik.com\/bio-tips\/category\/plot\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex387.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex387.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex387.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex387.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex387.png?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":1915,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/373-scatterplot-with-multiple-semantics-using-seaborn-library\/","url_meta":{"origin":6737,"position":4},"title":"#373 Scatterplot with multiple semantics using seaborn library","author":"gantovnik","date":"2023-08-09","format":false,"excerpt":"","rel":"","context":"In &quot;plot&quot;","block_context":{"text":"plot","link":"https:\/\/gantovnik.com\/bio-tips\/category\/plot\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex373.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex373.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex373.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex373.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex373.png?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":1109,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/193-animation-using-python\/","url_meta":{"origin":6737,"position":5},"title":"#193 Animation using python","author":"gantovnik","date":"2021-11-19","format":false,"excerpt":"","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex193.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex193.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex193.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex193.png?resize=700%2C400&ssl=1 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/6737","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=6737"}],"version-history":[{"count":3,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/6737\/revisions"}],"predecessor-version":[{"id":6749,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/6737\/revisions\/6749"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=6737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=6737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=6737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}