{"id":3886,"date":"2023-07-14T23:34:21","date_gmt":"2023-07-14T23:34:21","guid":{"rendered":"https:\/\/statorials.org\/nl\/cumulatief-aantal-pandas\/"},"modified":"2023-07-14T23:34:21","modified_gmt":"2023-07-14T23:34:21","slug":"cumulatief-aantal-pandas","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/cumulatief-aantal-pandas\/","title":{"rendered":"Hoe het cumulatieve getal in panda&#39;s te berekenen"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">U kunt de volgende methoden gebruiken om een cumulatief getal in een Panda DataFrame te berekenen:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Methode 1: Cumulatief tellen per groep<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>df[' <span style=\"color: #ff0000;\">cum_count<\/span> '] = df. <span style=\"color: #3366ff;\">groupby<\/span> (' <span style=\"color: #ff0000;\">col1<\/span> '). <span style=\"color: #3366ff;\">cumcount<\/span> ()\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Methode 2: cumulatieve rekening door meerdere groepen<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>df[' <span style=\"color: #ff0000;\">cum_count<\/span> '] = df. <span style=\"color: #3366ff;\">groupby<\/span> ([' <span style=\"color: #ff0000;\">col1<\/span> ', ' <span style=\"color: #ff0000;\">col2<\/span> ']). <span style=\"color: #3366ff;\">cumcount<\/span> ()<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">De volgende voorbeelden laten zien hoe u elke methode in de praktijk kunt gebruiken met de volgende panda&#8217;s DataFrame:<\/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<\/span>\ndf = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">team<\/span> ': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B'],\n                   ' <span style=\"color: #ff0000;\">position<\/span> ': ['G', 'G', 'G', 'F', 'G', 'G', 'F', 'F'],\n                   ' <span style=\"color: #ff0000;\">points<\/span> ': [14, 22, 25, 34, 30, 12, 10, 18]})\n\n<span style=\"color: #008080;\">#view DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n  team position points\n0 AG 14\n1 AG 22\n2 AG 25\n3AF 34\n4 BG 30\n5 BG 12\n6 BF 10\n7 BF 18\n<\/strong><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Voorbeeld 1: Cumulatief tellen per groep bij Panda&#8217;s<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">We kunnen de volgende syntaxis gebruiken om een nieuwe kolom te maken met de naam <strong>team_cum_count<\/strong> , waarin het cumulatieve aantal van elk <strong>team<\/strong> in het DataFrame wordt weergegeven:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#calculate cumulative count by team\n<span style=\"color: #000000;\">df[' <span style=\"color: #ff0000;\">team_cum_count<\/span> '] = df. <span style=\"color: #3366ff;\">groupby<\/span> (' <span style=\"color: #ff0000;\">team<\/span> '). <span style=\"color: #3366ff;\">cumcount<\/span> ()\n<\/span>\n#view updated DataFrame\n<span style=\"color: #000000;\"><span style=\"color: #008000;\">print<\/span> (df)\n\n  team position points team_cum_count\n0 AG 14 0\n1 AG 22 1\n2 AG 25 2\n3 AF 34 3\n4 BG 30 0\n5 BG 12 1\n6 BF 10 2\n7 BF 18 3<\/span><\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">De nieuwe kolom met de naam <strong>team_cum_count<\/strong> bevat de cumulatieve telling van elk <strong>team<\/strong> , beginnend met de waarde nul.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Als je wilt dat de telling bij \u00e9\u00e9n begint, voeg je er eenvoudig \u00e9\u00e9n toe aan het einde van de regel:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#calculate cumulative count (starting at 1) by team\n<span style=\"color: #000000;\">df[' <span style=\"color: #ff0000;\">team_cum_count<\/span> '] = df. <span style=\"color: #3366ff;\">groupby<\/span> (' <span style=\"color: #ff0000;\">team<\/span> '). <span style=\"color: #3366ff;\">cumcount<\/span> () + <span style=\"color: #008000;\">1\n<\/span><\/span>\n#view updated DataFrame\n<span style=\"color: #000000;\"><span style=\"color: #008000;\">print<\/span> (df)\n\n  team position points team_cum_count\n0 AG 14 1\n1 AG 22 2\n2 AG 25 3\n3 AF 34 4\n4 BG 30 1\n5 BG 12 2\n6 BF 10 3\n7 BF 18 4\n<\/span><\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">De nieuwe kolom met de naam <strong>team_cum_count<\/strong> bevat de cumulatieve telling van elk <strong>team<\/strong> , te beginnen met de waarde \u00e9\u00e9n.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Voorbeeld 2: Bereken het cumulatieve aantal per groep in Panda&#8217;s<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">We kunnen de volgende syntaxis gebruiken om een nieuwe kolom te maken met de naam <strong>team_pos_cum_count<\/strong> , waarin het cumulatieve aantal voor elk <strong>team<\/strong> en elke <strong>positie<\/strong> in het DataFrame wordt weergegeven:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#calculate cumulative count by team\n<span style=\"color: #000000;\">df[' <span style=\"color: #ff0000;\">team_pos_cum_count<\/span> '] = df. <span style=\"color: #3366ff;\">groupby<\/span> ([' <span style=\"color: #ff0000;\">team<\/span> ', ' <span style=\"color: #ff0000;\">position<\/span> ']). <span style=\"color: #3366ff;\">cumcount<\/span> () \n<\/span>\n#view updated DataFrame\n<span style=\"color: #000000;\"><span style=\"color: #008000;\">print<\/span> (df)\n\n  team position points team_pos_cum_count\n0 AG 14 0\n1 AG 22 1\n2 AG 25 2\n3 AF 34 0\n4 BG 30 0\n5 BG 12 1\n6 BF 10 0\n7 BF 18 1\n<\/span><\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">De nieuwe kolom met de naam <strong>team_pos_cum_count<\/strong> bevat de cumulatieve telling van elk <strong>team<\/strong> en <strong>elke positie<\/strong> , beginnend met een waarde van nul.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Opmerking<\/strong> : u kunt <a href=\"https:\/\/pandas.pydata.org\/pandas-docs\/stable\/reference\/api\/pandas.core.groupby.GroupBy.cumcount.html\" target=\"_blank\" rel=\"noopener\">hier<\/a> de volledige documentatie van de <b>cumcount-<\/b> functie in Panda&#8217;s vinden.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">In de volgende tutorials wordt uitgelegd hoe u andere veelvoorkomende taken in panda&#8217;s kunt uitvoeren:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/nl\/pandas-specifieke-somkolommen\/\" target=\"_blank\" rel=\"noopener\">Hoe specifieke kolommen in Panda&#8217;s op te tellen<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/pandas-somkolom-met-voorwaarde\/\" target=\"_blank\" rel=\"noopener\">Hoe kolommen op te tellen op basis van een voorwaarde in Pandas<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/pandas-omgekeerde-cumsum\/\" target=\"_blank\" rel=\"noopener\">Hoe een omgekeerde cumulatieve som in panda&#8217;s te berekenen<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>U kunt de volgende methoden gebruiken om een cumulatief getal in een Panda DataFrame te berekenen: Methode 1: Cumulatief tellen per groep df[&#8218; cum_count &#8218;] = df. groupby (&#8218; col1 &#8218;). cumcount () Methode 2: cumulatieve rekening door meerdere groepen df[&#8218; cum_count &#8218;] = df. groupby ([&#8218; col1 &#8218;, &#8218; col2 &#8218;]). cumcount () De [&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-3886","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 getal in panda&#039;s te berekenen \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe je een cumulatief aantal panda&#039;s berekent, met verschillende voorbeelden.\" \/>\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-aantal-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 getal in panda&#039;s te berekenen \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe je een cumulatief aantal panda&#039;s berekent, met verschillende voorbeelden.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/cumulatief-aantal-pandas\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-14T23:34:21+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-aantal-pandas\/\",\"url\":\"https:\/\/statorials.org\/nl\/cumulatief-aantal-pandas\/\",\"name\":\"Hoe het cumulatieve getal in panda&#39;s te berekenen \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-14T23:34:21+00:00\",\"dateModified\":\"2023-07-14T23:34:21+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe je een cumulatief aantal panda&#39;s berekent, met verschillende voorbeelden.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/cumulatief-aantal-pandas\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/cumulatief-aantal-pandas\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/cumulatief-aantal-pandas\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe het cumulatieve getal 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 getal in panda&#39;s te berekenen \u2013 Statorials","description":"In deze tutorial wordt uitgelegd hoe je een cumulatief aantal panda&#39;s berekent, met verschillende voorbeelden.","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-aantal-pandas\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe het cumulatieve getal in panda&#39;s te berekenen \u2013 Statorials","og_description":"In deze tutorial wordt uitgelegd hoe je een cumulatief aantal panda&#39;s berekent, met verschillende voorbeelden.","og_url":"https:\/\/statorials.org\/nl\/cumulatief-aantal-pandas\/","og_site_name":"Statorials","article_published_time":"2023-07-14T23:34:21+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-aantal-pandas\/","url":"https:\/\/statorials.org\/nl\/cumulatief-aantal-pandas\/","name":"Hoe het cumulatieve getal in panda&#39;s te berekenen \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-14T23:34:21+00:00","dateModified":"2023-07-14T23:34:21+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe je een cumulatief aantal panda&#39;s berekent, met verschillende voorbeelden.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/cumulatief-aantal-pandas\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/cumulatief-aantal-pandas\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/cumulatief-aantal-pandas\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe het cumulatieve getal 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\/3886","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=3886"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/3886\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=3886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=3886"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=3886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}