{"id":4234,"date":"2023-07-12T16:05:10","date_gmt":"2023-07-12T16:05:10","guid":{"rendered":"https:\/\/statorials.org\/nl\/pandas-groeperen-op-as_index\/"},"modified":"2023-07-12T16:05:10","modified_gmt":"2023-07-12T16:05:10","slug":"pandas-groeperen-op-as_index","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/pandas-groeperen-op-as_index\/","title":{"rendered":"Panda&#39;s: as_index gebruiken in groupby"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">U kunt het argument <strong>as_index<\/strong> in een pandas <strong>groupby()<\/strong> -bewerking gebruiken om op te geven of u wel of niet wilt dat de kolom waarop u hebt gegroepeerd, wordt gebruikt als de index van de uitvoer.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Het <strong>as_index<\/strong> argument kan <strong>True<\/strong> of <strong>False<\/strong> zijn.<\/span><\/p>\n<p> <span style=\"color: #000000;\">De standaardwaarde is <strong>Waar<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">In het volgende voorbeeld ziet u hoe u het argument <strong>as_index<\/strong> in de praktijk kunt gebruiken.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Voorbeeld: Hoe as_index te gebruiken in panda&#8217;s groupby<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Stel dat we het volgende panda&#8217;s DataFrame hebben dat het aantal punten weergeeft dat is gescoord door basketbalspelers van verschillende teams:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><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', 'C', 'C', 'C'],\n                   ' <span style=\"color: #ff0000;\">points<\/span> ': [12, 15, 17, 17, 19, 14, 15, 20, 24, 28]})\n                            \n<span style=\"color: #008080;\">#view DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n  team points\n0 to 12\n1 to 15\n2 to 17\n3 to 17\n4 to 19\n5 B 14\n6 B 15\n7 C 20\n8 C 24\n9 C 28<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">We kunnen de volgende syntaxis gebruiken om rijen te groeperen op <strong>teamkolom<\/strong> en de som van de <strong>puntenkolom<\/strong> te berekenen, terwijl we <strong>as_index=True<\/strong> opgeven om <strong>team<\/strong> als uitvoerindex te gebruiken:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#group rows by team and calculate sum of points\n<span style=\"color: #000000;\"><span style=\"color: #008000;\">print<\/span> ( <span style=\"color: #3366ff;\">df.groupby<\/span> (' <span style=\"color: #ff0000;\">team<\/span> ', as_index= <span style=\"color: #008000;\">True<\/span> ) <span style=\"color: #3366ff;\">.sum<\/span> ())\n<\/span>\n<span style=\"color: #000000;\">points\nteam        \nAt 80\nB29\nC 72<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">De uitvoer toont de som van de waarden in de <strong>puntenkolom<\/strong> , gegroepeerd op de waarden in de <strong>teamkolom<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Houd er rekening mee dat de <strong>teamkolom<\/strong> wordt gebruikt als de index van de uitvoer.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Als we in plaats daarvan <strong>as_index=False<\/strong> opgeven, wordt de <strong>teamkolom<\/strong> niet gebruikt als de uitvoerindex:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#group rows by team and calculate sum of points\n<span style=\"color: #000000;\"><span style=\"color: #008000;\">print<\/span> ( <span style=\"color: #3366ff;\">df.groupby<\/span> (' <span style=\"color: #ff0000;\">team<\/span> ', as_index= <span style=\"color: #008000;\">False<\/span> ) <span style=\"color: #3366ff;\">.sum<\/span> ())\n\n  team points\n0 to 80\n1 B 29\n2 C 72\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Merk op dat <strong>team<\/strong> nu als kolom in de uitvoer wordt gebruikt en dat de indexkolom eenvoudigweg genummerd is van 0-2.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Opmerking<\/strong> : u kunt de volledige documentatie van de pandas <strong>groupby()-<\/strong> bewerking <a href=\"https:\/\/pandas.pydata.org\/docs\/reference\/api\/pandas.DataFrame.groupby.html\" target=\"_blank\" rel=\"noopener\">hier<\/a> 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 bewerkingen in panda&#8217;s kunt uitvoeren:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/nl\/pandas-groupby-krijg-groep\/\" target=\"_blank\" rel=\"noopener\">Hoe u een groep kunt krijgen na het gebruik van Pandas Groupby<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/pandas-groupby-naar-dataframe\/\" target=\"_blank\" rel=\"noopener\">Hoe Pandas GroupBy-uitvoer naar DataFrame te converteren<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/pandas-groupby-toepassen\/\" target=\"_blank\" rel=\"noopener\">Een functie toepassen op Panda&#8217;s Groupby<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>U kunt het argument as_index in een pandas groupby() -bewerking gebruiken om op te geven of u wel of niet wilt dat de kolom waarop u hebt gegroepeerd, wordt gebruikt als de index van de uitvoer. Het as_index argument kan True of False zijn. De standaardwaarde is Waar . In het volgende voorbeeld ziet u [&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-4234","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>Panda&#039;s: hoe as_index in groupby te gebruiken \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u het argument as_index in groupby() in panda&#039;s kunt gebruiken, inclusief 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-op-as_index\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Panda&#039;s: hoe as_index in groupby te gebruiken \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u het argument as_index in groupby() in panda&#039;s kunt gebruiken, inclusief voorbeelden.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/pandas-groeperen-op-as_index\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-12T16:05:10+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-op-as_index\/\",\"url\":\"https:\/\/statorials.org\/nl\/pandas-groeperen-op-as_index\/\",\"name\":\"Panda&#39;s: hoe as_index in groupby te gebruiken \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-12T16:05:10+00:00\",\"dateModified\":\"2023-07-12T16:05:10+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u het argument as_index in groupby() in panda&#39;s kunt gebruiken, inclusief voorbeelden.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/pandas-groeperen-op-as_index\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/pandas-groeperen-op-as_index\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/pandas-groeperen-op-as_index\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Panda&#39;s: as_index gebruiken in 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":"Panda&#39;s: hoe as_index in groupby te gebruiken \u2013 Statorials","description":"In deze tutorial wordt uitgelegd hoe u het argument as_index in groupby() in panda&#39;s kunt gebruiken, inclusief 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-op-as_index\/","og_locale":"de_DE","og_type":"article","og_title":"Panda&#39;s: hoe as_index in groupby te gebruiken \u2013 Statorials","og_description":"In deze tutorial wordt uitgelegd hoe u het argument as_index in groupby() in panda&#39;s kunt gebruiken, inclusief voorbeelden.","og_url":"https:\/\/statorials.org\/nl\/pandas-groeperen-op-as_index\/","og_site_name":"Statorials","article_published_time":"2023-07-12T16:05:10+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-op-as_index\/","url":"https:\/\/statorials.org\/nl\/pandas-groeperen-op-as_index\/","name":"Panda&#39;s: hoe as_index in groupby te gebruiken \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-12T16:05:10+00:00","dateModified":"2023-07-12T16:05:10+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u het argument as_index in groupby() in panda&#39;s kunt gebruiken, inclusief voorbeelden.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/pandas-groeperen-op-as_index\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/pandas-groeperen-op-as_index\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/pandas-groeperen-op-as_index\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Panda&#39;s: as_index gebruiken in 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\/4234","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=4234"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/4234\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=4234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=4234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=4234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}