{"id":2572,"date":"2023-07-21T16:37:26","date_gmt":"2023-07-21T16:37:26","guid":{"rendered":"https:\/\/statorials.org\/nl\/cumulatief-percentage-pandas\/"},"modified":"2023-07-21T16:37:26","modified_gmt":"2023-07-21T16:37:26","slug":"cumulatief-percentage-pandas","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/cumulatief-percentage-pandas\/","title":{"rendered":"Hoe het cumulatieve percentage in panda&#39;s te berekenen"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">U kunt de volgende basissyntaxis gebruiken om het cumulatieve percentage van waarden in een kolom van een Panda DataFrame te berekenen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate cumulative sum of column\n<\/span>df[' <span style=\"color: #ff0000;\">cum_sum<\/span> '] = df[' <span style=\"color: #ff0000;\">col1<\/span> ']. <span style=\"color: #3366ff;\">cumsum<\/span> ()\n\n<span style=\"color: #008080;\">#calculate cumulative percentage of column (rounded to 2 decimal places)\n<\/span>df[' <span style=\"color: #ff0000;\">cum_percent<\/span> '] = round( <span style=\"color: #008000;\">100<\/span> *df. <span style=\"color: #3366ff;\">cum_sum<\/span> \/df[' <span style=\"color: #ff0000;\">col1<\/span> ']. <span style=\"color: #3366ff;\">sum<\/span> (), <span style=\"color: #008000;\">2<\/span> )\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Het volgende voorbeeld laat zien hoe u deze syntaxis in de praktijk kunt gebruiken.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld: Bereken het cumulatieve percentage onder panda&#8217;s<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Stel dat we het volgende panda&#8217;s DataFrame hebben dat het aantal eenheden weergeeft dat een bedrijf in opeenvolgende jaren verkoopt:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">import<\/span> pandas <span style=\"color: #008000;\">as<\/span> pd\n\n<span style=\"color: #008080;\">#createDataFrame\n<span style=\"color: #000000;\">df = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">year<\/span> ': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\n                   ' <span style=\"color: #ff0000;\">units_sold<\/span> ': [60, 75, 77, 87, 104, 134, 120, 125, 140, 150]})\n\n<span style=\"color: #008080;\">#view DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n   year units_sold\n0 1 60\n1 2 75\n2 3 77\n3 4 87\n4 5 104\n5 6 134\n6 7 120\n7 8 125\n8 9 140\n9 10 150\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">Vervolgens kunnen we de volgende code gebruiken om een kolom toe te voegen die het cumulatieve aantal verkochte eenheden en het cumulatieve percentage verkochte eenheden weergeeft:<\/span><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#calculate cumulative sum of units sold\n<\/span>df[' <span style=\"color: #ff0000;\">cum_sum<\/span> '] = df[' <span style=\"color: #ff0000;\">units_sold<\/span> ']. <span style=\"color: #3366ff;\">cumsum<\/span> ()\n\n<span style=\"color: #008080;\">#calculate cumulative percentage of units sold\n<\/span>df[' <span style=\"color: #ff0000;\">cum_percent<\/span> '] = round( <span style=\"color: #008000;\">100<\/span> *df. <span style=\"color: #3366ff;\">cum_sum<\/span> \/df[' <span style=\"color: #ff0000;\">units_sold<\/span> ']. <span style=\"color: #3366ff;\">sum<\/span> (), <span style=\"color: #008000;\">2<\/span> )\n\n<span style=\"color: #008080;\">#view updated DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n   year units_sold cum_sum cum_percent\n0 1 60 60 5.60\n1 2 75 135 12.59\n2 3 77 212 19.78\n3 4 87 299 27.89\n4 5 104 403 37.59\n5 6 134 537 50.09\n6 7 120 657 61.29\n7 8 125 782 72.95\n8 9 140 922 86.01\n9 10 150 1072 100.00\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">We interpreteren de cumulatieve percentages als volgt:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>5,60%<\/strong> van alle verkopen werd in het eerste jaar gerealiseerd.<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>12,59<\/strong> van alle verkopen werden gerealiseerd in jaar 1 en 2 samen.<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>19,78%<\/strong> van alle verkopen werd behaald in de jaren 1, 2 en 3 samen.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Enzovoort.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Merk op dat u eenvoudigweg de waarde in de functie <strong>round()<\/strong> kunt wijzigen om ook het aantal weergegeven decimalen te wijzigen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">We kunnen in plaats daarvan bijvoorbeeld het cumulatieve percentage afronden op nul decimalen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#calculate cumulative sum of units sold\n<\/span>df[' <span style=\"color: #ff0000;\">cum_sum<\/span> '] = df[' <span style=\"color: #ff0000;\">units_sold<\/span> ']. <span style=\"color: #3366ff;\">cumsum<\/span> ()\n\n<span style=\"color: #008080;\">#calculate cumulative percentage of units sold\n<\/span>df[' <span style=\"color: #ff0000;\">cum_percent<\/span> '] = round( <span style=\"color: #008000;\">100<\/span> *df. <span style=\"color: #3366ff;\">cum_sum<\/span> \/df[' <span style=\"color: #ff0000;\">units_sold<\/span> ']. <span style=\"color: #3366ff;\">sum<\/span> (), <span style=\"color: #008000;\">0<\/span> )\n\n<span style=\"color: #008080;\">#view updated DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n   year units_sold cum_sum cum_percent\n0 1 60 60 6.0\n1 2 75 135 13.0\n2 3 77 212 20.0\n3 4 87 299 28.0\n4 5 104 403 38.0\n5 6 134 537 50.0\n6 7 120 657 61.0\n7 8 125 782 73.0\n8 9 140 922 86.0\n9 10 150 1072 100.0<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Cumulatieve percentages worden nu afgerond op nul decimalen.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">In de volgende tutorials wordt uitgelegd hoe u andere veelvoorkomende bewerkingen in Python uitvoert:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/nl\/python-frequentietabellen\/\" target=\"_blank\" rel=\"noopener\">Hoe u frequentietabellen maakt in Python<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/relatieve-frequentiepython\/\" target=\"_blank\" rel=\"noopener\">Hoe de relatieve frequentie in Python te berekenen<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>U kunt de volgende basissyntaxis gebruiken om het cumulatieve percentage van waarden in een kolom van een Panda DataFrame te berekenen: #calculate cumulative sum of column df[&#8218; cum_sum &#8218;] = df[&#8218; col1 &#8218;]. cumsum () #calculate cumulative percentage of column (rounded to 2 decimal places) df[&#8218; cum_percent &#8218;] = round( 100 *df. cum_sum \/df[&#8218; col1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-2572","post","type-post","status-publish","format-standard","hentry","category-gids"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Hoe het cumulatieve percentage in panda&#039;s te berekenen - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt met voorbeelden uitgelegd hoe u het cumulatieve percentage van een kolom in panda&#039;s kunt berekenen.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/nl\/cumulatief-percentage-pandas\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe het cumulatieve percentage in panda&#039;s te berekenen - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt met voorbeelden uitgelegd hoe u het cumulatieve percentage van een kolom in panda&#039;s kunt berekenen.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/cumulatief-percentage-pandas\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-21T16:37:26+00:00\" \/>\n<meta name=\"author\" content=\"Dr.benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr.benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"2\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/cumulatief-percentage-pandas\/\",\"url\":\"https:\/\/statorials.org\/nl\/cumulatief-percentage-pandas\/\",\"name\":\"Hoe het cumulatieve percentage in panda&#39;s te berekenen - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-21T16:37:26+00:00\",\"dateModified\":\"2023-07-21T16:37:26+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt met voorbeelden uitgelegd hoe u het cumulatieve percentage van een kolom in panda&#39;s kunt berekenen.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/cumulatief-percentage-pandas\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/cumulatief-percentage-pandas\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/cumulatief-percentage-pandas\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe het cumulatieve percentage in panda&#39;s te berekenen\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/nl\/#website\",\"url\":\"https:\/\/statorials.org\/nl\/\",\"name\":\"Statorials\",\"description\":\"Uw gids voor statistische competentie\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/nl\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"de\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\",\"name\":\"Dr.benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr.benjamin anderson\"},\"description\":\"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder\",\"sameAs\":[\"http:\/\/statorials.org\/nl\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Hoe het cumulatieve percentage in panda&#39;s te berekenen - Statorials","description":"In deze tutorial wordt met voorbeelden uitgelegd hoe u het cumulatieve percentage van een kolom in panda&#39;s kunt berekenen.","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:\/\/statorials.org\/nl\/cumulatief-percentage-pandas\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe het cumulatieve percentage in panda&#39;s te berekenen - Statorials","og_description":"In deze tutorial wordt met voorbeelden uitgelegd hoe u het cumulatieve percentage van een kolom in panda&#39;s kunt berekenen.","og_url":"https:\/\/statorials.org\/nl\/cumulatief-percentage-pandas\/","og_site_name":"Statorials","article_published_time":"2023-07-21T16:37:26+00:00","author":"Dr.benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr.benjamin anderson","Gesch\u00e4tzte Lesezeit":"2\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/nl\/cumulatief-percentage-pandas\/","url":"https:\/\/statorials.org\/nl\/cumulatief-percentage-pandas\/","name":"Hoe het cumulatieve percentage in panda&#39;s te berekenen - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-21T16:37:26+00:00","dateModified":"2023-07-21T16:37:26+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt met voorbeelden uitgelegd hoe u het cumulatieve percentage van een kolom in panda&#39;s kunt berekenen.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/cumulatief-percentage-pandas\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/cumulatief-percentage-pandas\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/cumulatief-percentage-pandas\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe het cumulatieve percentage in panda&#39;s te berekenen"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/nl\/#website","url":"https:\/\/statorials.org\/nl\/","name":"Statorials","description":"Uw gids voor statistische competentie","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/nl\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"de"},{"@type":"Person","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219","name":"Dr.benjamin anderson","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/","url":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr.benjamin anderson"},"description":"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder","sameAs":["http:\/\/statorials.org\/nl"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/2572","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/comments?post=2572"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/2572\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=2572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=2572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=2572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}