{"id":2352,"date":"2023-07-22T15:53:14","date_gmt":"2023-07-22T15:53:14","guid":{"rendered":"https:\/\/statorials.org\/nl\/pandas-groeperen-per-telling-uniek\/"},"modified":"2023-07-22T15:53:14","modified_gmt":"2023-07-22T15:53:14","slug":"pandas-groeperen-per-telling-uniek","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/pandas-groeperen-per-telling-uniek\/","title":{"rendered":"Hoe u unieke waarden kunt tellen met pandas groupby"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">U kunt de volgende basissyntaxis gebruiken om het aantal unieke waarden per groep in een pandas DataFrame te tellen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>df. <span style=\"color: #3366ff;\">groupby<\/span> (' <span style=\"color: #ff0000;\">group_column<\/span> ')[' <span style=\"color: #ff0000;\">count_column<\/span> ']. <span style=\"color: #3366ff;\">nunique<\/span> ()\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">De volgende voorbeelden laten zien hoe u deze syntaxis kunt gebruiken met het volgende 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\n<\/span>df = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">team<\/span> ': ['A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B'],\n                   ' <span style=\"color: #ff0000;\">position<\/span> ': ['G', 'G', 'G', 'F', 'F', 'G', 'G', 'F', 'F', 'F'],\n                   ' <span style=\"color: #ff0000;\">points<\/span> ': [5, 7, 7, 9, 12, 9, 9, 4, 7, 7],\n                   ' <span style=\"color: #ff0000;\">rebounds<\/span> ': [11, 8, 10, 6, 6, 5, 9, 12, 13, 15]})\n\n<span style=\"color: #008080;\">#view DataFrame\n<\/span>df\n\n\tteam position points rebounds\n0 A G 5 11\n1 A G 7 8\n2 A G 7 10\n3 A F 9 6\n4 A F 12 6\n5 B G 9 5\n6 B G 9 9\n7 B F 4 12\n8 B F 7 13\n9 B F 7 15\n<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld 1: Groepeer op een kolom en tel unieke waarden<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe u voor elk team het aantal unieke waarden in de kolom &#8222;punten&#8220; kunt tellen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#count number of unique values in 'points' column grouped by 'team' column\n<span style=\"color: #000000;\">df. <span style=\"color: #3366ff;\">groupby<\/span> (' <span style=\"color: #ff0000;\">team<\/span> ')[' <span style=\"color: #ff0000;\">points<\/span> ']. <span style=\"color: #3366ff;\">nunique<\/span> ()\n\nteam\nAt 4\nB 3\nName: points, dtype: int64<\/span>\n<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Uit het resultaat kunnen we zien:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">Er zijn <strong>4<\/strong> unieke \u201cpunt\u201d-waarden voor Team A.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Er zijn <strong>3<\/strong> unieke \u201cpunt\u201d-waarden voor Team B.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Merk op dat we ook de functie <strong>unique()<\/strong> kunnen gebruiken om elke unieke &#8222;punt&#8220;-waarde per team weer te geven:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#display unique values in 'points' column grouped by 'team'<\/span>\ndf. <span style=\"color: #3366ff;\">groupby<\/span> (' <span style=\"color: #ff0000;\">team<\/span> ')[' <span style=\"color: #ff0000;\">points<\/span> ']. <span style=\"color: #3366ff;\">single<\/span> ()\n\nteam\nA [5, 7, 9, 12]\nB [9, 4, 7]\nName: points, dtype: object<\/span><\/span><\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld 2: Groepeer op meerdere kolommen en tel unieke waarden<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe u het aantal unieke waarden in de kolom &#8222;punten&#8220; kunt tellen, gegroepeerd op team <em>en<\/em> positie:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#count number of unique values in 'points' column grouped by 'team' and 'position'\n<span style=\"color: #000000;\">df. <span style=\"color: #3366ff;\">groupby<\/span> ([' <span style=\"color: #ff0000;\">team<\/span> ', ' <span style=\"color: #ff0000;\">position<\/span> '])[' <span style=\"color: #ff0000;\">points<\/span> ']. <span style=\"color: #3366ff;\">nunique<\/span> ()\n\nteam position\nAF2\n      G2\nBF 2\n      G 1\nName: points, dtype: int64<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Uit het resultaat kunnen we zien:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">Er zijn <strong>2<\/strong> unieke \u201cpunt\u201d-waarden voor spelers in positie \u201cF\u201d van Team A.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Er zijn <strong>2<\/strong> unieke \u201cpunt\u201d-waarden voor spelers in de \u201cG\u201d-positie van Team A.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Er zijn <strong>2<\/strong> unieke \u201cpunt\u201d-waarden voor spelers in positie \u201cF\u201d van Team B.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Er is <strong>1<\/strong> unieke \u201cpunt\u201d-waarde voor spelers in positie \u201cG\u201d van Team B.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Opnieuw kunnen we de functie <strong>unique()<\/strong> gebruiken om elke unieke &#8222;punt&#8220;-waarde per team en per positie weer te geven:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#display unique values in 'points' column grouped by 'team' and 'position'\n<span style=\"color: #000000;\">df. <span style=\"color: #3366ff;\">groupby<\/span> ([' <span style=\"color: #ff0000;\">team<\/span> ', ' <span style=\"color: #ff0000;\">position<\/span> '])[' <span style=\"color: #ff0000;\">points<\/span> ']. <span style=\"color: #3366ff;\">single<\/span> ()\n\nteam position\nAF [9, 12]\n      G [5, 7]\nBF [4, 7]\n      G [9]\nName: points, dtype: object<\/span><\/span><\/strong><\/pre>\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 panda&#8217;s kunt uitvoeren:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/nl\/pandas-unieke-waarden-in-kolom\/\" target=\"_blank\" rel=\"noopener\">Panda&#8217;s: unieke waarden in een kolom vinden<\/a><br \/><a href=\"https:\/\/statorials.org\/nl\/enkele-pandas-meerdere-kolommen\/\" target=\"_blank\" rel=\"noopener\">Panda&#8217;s: hoe vind je unieke waarden in meerdere kolommen?<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/pandas-telt-specifieke-waarde-in-kolom\/\" target=\"_blank\" rel=\"noopener\">Panda&#8217;s: hoe u exemplaren met een specifieke waarde in een kolom kunt tellen<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>U kunt de volgende basissyntaxis gebruiken om het aantal unieke waarden per groep in een pandas DataFrame te tellen: df. groupby (&#8218; group_column &#8218;)[&#8218; count_column &#8218;]. nunique () De volgende voorbeelden laten zien hoe u deze syntaxis kunt gebruiken met het volgende DataFrame: import pandas as pd #createDataFrame df = pd. DataFrame ({&#8218; team &#8218;: [&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-2352","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 u unieke waarden kunt tellen met Pandas GroupBy - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe je het aantal unieke waarden kunt tellen met behulp van de panda&#039;s GroupBy-functie, 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\/pandas-groeperen-per-telling-uniek\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe u unieke waarden kunt tellen met Pandas GroupBy - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe je het aantal unieke waarden kunt tellen met behulp van de panda&#039;s GroupBy-functie, met verschillende voorbeelden.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/pandas-groeperen-per-telling-uniek\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-22T15:53:14+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\/pandas-groeperen-per-telling-uniek\/\",\"url\":\"https:\/\/statorials.org\/nl\/pandas-groeperen-per-telling-uniek\/\",\"name\":\"Hoe u unieke waarden kunt tellen met Pandas GroupBy - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-22T15:53:14+00:00\",\"dateModified\":\"2023-07-22T15:53:14+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe je het aantal unieke waarden kunt tellen met behulp van de panda&#39;s GroupBy-functie, met verschillende voorbeelden.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/pandas-groeperen-per-telling-uniek\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/pandas-groeperen-per-telling-uniek\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/pandas-groeperen-per-telling-uniek\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe u unieke waarden kunt tellen met pandas groupby\"}]},{\"@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 u unieke waarden kunt tellen met Pandas GroupBy - Statorials","description":"In deze tutorial wordt uitgelegd hoe je het aantal unieke waarden kunt tellen met behulp van de panda&#39;s GroupBy-functie, 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\/pandas-groeperen-per-telling-uniek\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe u unieke waarden kunt tellen met Pandas GroupBy - Statorials","og_description":"In deze tutorial wordt uitgelegd hoe je het aantal unieke waarden kunt tellen met behulp van de panda&#39;s GroupBy-functie, met verschillende voorbeelden.","og_url":"https:\/\/statorials.org\/nl\/pandas-groeperen-per-telling-uniek\/","og_site_name":"Statorials","article_published_time":"2023-07-22T15:53:14+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\/pandas-groeperen-per-telling-uniek\/","url":"https:\/\/statorials.org\/nl\/pandas-groeperen-per-telling-uniek\/","name":"Hoe u unieke waarden kunt tellen met Pandas GroupBy - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-22T15:53:14+00:00","dateModified":"2023-07-22T15:53:14+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe je het aantal unieke waarden kunt tellen met behulp van de panda&#39;s GroupBy-functie, met verschillende voorbeelden.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/pandas-groeperen-per-telling-uniek\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/pandas-groeperen-per-telling-uniek\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/pandas-groeperen-per-telling-uniek\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe u unieke waarden kunt tellen met pandas groupby"}]},{"@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\/2352","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=2352"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/2352\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=2352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=2352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=2352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}