{"id":55,"date":"2024-07-29T07:18:43","date_gmt":"2024-07-29T07:18:43","guid":{"rendered":"https:\/\/scienceofquantity.com\/index.php\/2024\/07\/29\/code-execution-output-12\/"},"modified":"2024-07-29T07:18:43","modified_gmt":"2024-07-29T07:18:43","slug":"code-execution-output-12","status":"publish","type":"post","link":"https:\/\/scienceofquantity.com\/index.php\/2024\/07\/29\/code-execution-output-12\/","title":{"rendered":"Code Execution Output"},"content":{"rendered":"<body><h2>Python Code Example<\/h2>\n<pre><code class=\"language-python\">\nimport pandas as pd\n\n# Initial data\ndata = {\n    \"Recursion\": [1],\n    \"Number of Ellipses\": [3],\n    \"Number of Chords\": [6],\n    \"Number of Foci\": [6],\n    \"Number of Points P\": [3],\n    \"Ellipses\": [['E_1_a', 'E_1_b', 'E_1_c']],\n    \"Chords\": [['C_1_a', 'C_1_b', 'C_1_c', 'C_1_d', 'C_1_e', 'C_1_f']],\n    \"Foci\": [['F_1_a', 'F_1_b', 'F_1_c', 'F_1_d', 'F_1_e', 'F_1_f']],\n    \"Points P\": [['P_1_a', 'P_1_b', 'P_1_c']],\n    \"Centers\": [[(3.5, 0), (1.0, 0), (6.0, 0)]],\n    \"Points P Coordinates\": [[(3.5000000000000004, 3.122498999199199), (1.7949984102035197, 0.9929526960901777), (5.20500158979648, 0.9929526960901777)]],\n    \"Chord Lengths\": [[[4.0, 3.9999999999999996], [1.9968740067521995, 1.0031259939978001], [1.0031259939978003, 1.9968740067522]]]\n}\n\ndf = pd.DataFrame(data)\n\n# Unnesting the data into 6 rows\nunnested_data = {\n    \"Recursion\": [],\n    \"Ellipses\": [],\n    \"Chords\": [],\n    \"Foci\": [],\n    \"Points P\": [],\n    \"Centers\": [],\n    \"Points P Coordinates\": [],\n    \"Chord Lengths\": []\n}\n\nfor i in range(df[\"Number of Chords\"][0]):\n    ellipse_index = i % df[\"Number of Ellipses\"][0]\n    foci_index = i % df[\"Number of Foci\"][0]\n    point_index = i % df[\"Number of Points P\"][0]\n    center_index = i % len(df[\"Centers\"][0])\n    \n    unnested_data[\"Recursion\"].append(df[\"Recursion\"][0])\n    unnested_data[\"Ellipses\"].append(df[\"Ellipses\"][0][ellipse_index])\n    unnested_data[\"Chords\"].append(df[\"Chords\"][0][i])\n    unnested_data[\"Foci\"].append(df[\"Foci\"][0][foci_index])\n    unnested_data[\"Points P\"].append(df[\"Points P\"][0][point_index])\n    unnested_data[\"Centers\"].append(df[\"Centers\"][0][center_index])\n    unnested_data[\"Points P Coordinates\"].append(df[\"Points P Coordinates\"][0][center_index])\n    unnested_data[\"Chord Lengths\"].append(df[\"Chord Lengths\"][0][ellipse_index][i % 2])\n\nunnested_df = pd.DataFrame(unnested_data)\ndisplay(unnested_df)\n<\/code><\/pre>\n<h2>Output<\/h2>\n<pre><\/pre>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>Python Code Example import pandas as pd # Initial data data = { &#8220;Recursion&#8221;: [1], &#8220;Number of Ellipses&#8221;: [3], &#8220;Number of Chords&#8221;: [6], &#8220;Number of Foci&#8221;: [6], &#8220;Number of Points P&#8221;: [3], &#8220;Ellipses&#8221;: [[&#8216;E_1_a&#8217;, &#8216;E_1_b&#8217;, &#8216;E_1_c&#8217;]], &#8220;Chords&#8221;: [[&#8216;C_1_a&#8217;, &#8216;C_1_b&#8217;, &#8216;C_1_c&#8217;, &#8216;C_1_d&#8217;, &#8216;C_1_e&#8217;, &#8216;C_1_f&#8217;]], &#8220;Foci&#8221;: [[&#8216;F_1_a&#8217;, &#8216;F_1_b&#8217;, &#8216;F_1_c&#8217;, &#8216;F_1_d&#8217;, &#8216;F_1_e&#8217;, &#8216;F_1_f&#8217;]], &#8220;Points P&#8221;: [[&#8216;P_1_a&#8217;, &#8216;P_1_b&#8217;, &#8216;P_1_c&#8217;]], &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/scienceofquantity.com\/index.php\/2024\/07\/29\/code-execution-output-12\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Code Execution Output&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-55","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scienceofquantity.com\/index.php\/wp-json\/wp\/v2\/posts\/55","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scienceofquantity.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scienceofquantity.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scienceofquantity.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/scienceofquantity.com\/index.php\/wp-json\/wp\/v2\/comments?post=55"}],"version-history":[{"count":0,"href":"https:\/\/scienceofquantity.com\/index.php\/wp-json\/wp\/v2\/posts\/55\/revisions"}],"wp:attachment":[{"href":"https:\/\/scienceofquantity.com\/index.php\/wp-json\/wp\/v2\/media?parent=55"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scienceofquantity.com\/index.php\/wp-json\/wp\/v2\/categories?post=55"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scienceofquantity.com\/index.php\/wp-json\/wp\/v2\/tags?post=55"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}