{"id":1522,"date":"2023-07-26T01:16:58","date_gmt":"2023-07-26T01:16:58","guid":{"rendered":"https:\/\/statorials.org\/nl\/python-contingentietabel\/"},"modified":"2023-07-26T01:16:58","modified_gmt":"2023-07-26T01:16:58","slug":"python-contingentietabel","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/python-contingentietabel\/","title":{"rendered":"Hoe u een contingentietabel maakt in python"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Een <strong>kruistabel<\/strong> is een soort tabel die de relatie tussen twee categorische variabelen samenvat.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Om een kruistabel in Python te maken, kunnen we de functie <a href=\"https:\/\/pandas.pydata.org\/docs\/reference\/api\/pandas.crosstab.html\" target=\"_blank\" rel=\"noopener\">pandas.crosstab()<\/a> gebruiken, die de volgende syntaxis gebruikt:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>pandas.crosstab(index, kolommen)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Goud:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>index:<\/strong> naam van de variabele die moet worden weergegeven in de rijen van de kruistabel<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>kolommen:<\/strong> naam van de variabele die moet worden weergegeven in de kolommen van de kruistabel<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Het volgende stapsgewijze voorbeeld laat zien hoe u deze functie kunt gebruiken om een kruistabel in Python te maken.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Stap 1: Cre\u00eber de gegevens<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Laten we eerst een dataset maken die informatie weergeeft over twintig verschillende productbestellingen, inclusief het type gekochte product (tv, computer of radio) en het land (A, B of C) waarin het product is gekocht:<\/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;\">#create data<\/span>\ndf = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({'Order': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10,\n                            11, 12, 13, 14, 15, 16, 17, 18, 19, 20],\n                   'Product': ['TV', 'TV', 'Comp', 'TV', 'TV', 'Comp',\n                               'Comp', 'Comp', 'TV', 'Radio', 'TV', 'Radio', 'Radio',\n                               'Radio', 'Comp', 'Comp', 'TV', 'TV', 'Radio', 'TV'],\n                   'Country': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B', 'B', 'B',\n                               'B', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C']})\n\n<span style=\"color: #008080;\">#view data\n<\/span>df\n\n        Order Product Country\n0 1 TV A\n1 2 TV A\n2 3 Comp A\n3 4 TV A\n4 5 TV B\n5 6 Comp B\n6 7 Comp B\n7 8 Comp B\n8 9 TV B\n9 10 Radio B\n10 11 TV B\n11 12 Radio B\n12 13 Radio C\n13 14 Radio C\n14 15 Comp C\n15 16 Comp C\n16 17 TV C\n17 18 TV C\n18 19 Radio C\n19 20 TV C<\/strong><\/pre>\n<h3> <strong><span style=\"color: #000000;\">Stap 2: Maak de kruistabel<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe u een kruistabel kunt maken om het aantal van elk product te tellen dat door elk land is besteld:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create contingency table<\/span>\np.d. <span style=\"color: #3366ff;\">crosstab<\/span> (index=df[' <span style=\"color: #008000;\">Country<\/span> '], columns=df[' <span style=\"color: #008000;\">Product<\/span> '])\n\nProduct Comp Radio TV\nCountry\t\t\t\nA 1 0 3\nB 3 2 3\nC 2 3 3<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Zo interpreteert u de tabel:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">Er is in totaal <strong>1<\/strong> computer aangeschaft in land A.<\/span><\/li>\n<li> <span style=\"color: #000000;\">In land B zijn in totaal <strong>3<\/strong> computers aangeschaft.<\/span><\/li>\n<li> <span style=\"color: #000000;\">In land C zijn in totaal <strong>2<\/strong> computers aangeschaft.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Er zijn in totaal <strong>0<\/strong> radio&#8217;s aangeschaft in land A.<\/span><\/li>\n<li> <span style=\"color: #000000;\">In land B zijn in totaal <strong>2<\/strong> radio\u2019s aangeschaft.<\/span><\/li>\n<li> <span style=\"color: #000000;\">In land C zijn in totaal <strong>3<\/strong> radio\u2019s aangeschaft.<\/span><\/li>\n<li> <span style=\"color: #000000;\">In land A zijn <strong>in totaal 3<\/strong> televisies aangeschaft.<\/span><\/li>\n<li> <span style=\"color: #000000;\">In land B zijn <strong>in totaal 3<\/strong> televisies aangeschaft.<\/span><\/li>\n<li> <span style=\"color: #000000;\">In land C zijn in totaal <strong>3<\/strong> televisies aangeschaft.<\/span><\/li>\n<\/ul>\n<h3> <strong><span style=\"color: #000000;\">Stap 3: Voeg margetotalen toe aan de kruistabel<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">We kunnen het argument <strong>margins=True<\/strong> gebruiken om de margetotalen toe te voegen aan de kruistabel:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#add margins to contingency table<\/span>\np.d. <span style=\"color: #3366ff;\">crosstab<\/span> (index=df[' <span style=\"color: #008000;\">Country<\/span> '], columns=df[' <span style=\"color: #008000;\">Product<\/span> '], margins= <span style=\"color: #008000;\">True<\/span> )\n\nProduct Comp Radio TV All\nCountry\t\t\t\t\nA 1 0 3 4\nB 3 2 3 8\nC 2 3 3 8\nAll 6 5 9 20<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">De manier om de tabelwaarden te interpreteren is als volgt:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Regeltotalen:<\/strong><\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">Er zijn in totaal <strong>4<\/strong> bestellingen geplaatst vanuit land A.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Er zijn in totaal <strong>8<\/strong> bestellingen geplaatst vanuit land B.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Er zijn in totaal <strong>8<\/strong> bestellingen geplaatst vanuit land C.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\"><strong>Kolomtotalen:<\/strong><\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">Er zijn in totaal <strong>6<\/strong> computers aangeschaft.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Er zijn in totaal <strong>5<\/strong> radio&#8217;s aangeschaft.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Er zijn in totaal <strong>9<\/strong> televisies aangeschaft.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Uit de waarde rechtsonder in de tabel blijkt dat er in totaal <strong>20<\/strong> producten uit alle landen zijn besteld.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/nl\/kruistabel-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe u een kruistabel maakt in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/excel-kruistabel\/\" target=\"_blank\" rel=\"noopener\">Hoe u een contingentietabel maakt in Excel<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Een kruistabel is een soort tabel die de relatie tussen twee categorische variabelen samenvat. Om een kruistabel in Python te maken, kunnen we de functie pandas.crosstab() gebruiken, die de volgende syntaxis gebruikt: pandas.crosstab(index, kolommen) Goud: index: naam van de variabele die moet worden weergegeven in de rijen van de kruistabel kolommen: naam van de variabele [&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-1522","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 een contingentietabel maakt in Python<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u een kruistabel in Python maakt, met een stapsgewijs voorbeeld.\" \/>\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\/python-contingentietabel\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe u een contingentietabel maakt in Python\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u een kruistabel in Python maakt, met een stapsgewijs voorbeeld.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/python-contingentietabel\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-26T01:16:58+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=\"3\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/python-contingentietabel\/\",\"url\":\"https:\/\/statorials.org\/nl\/python-contingentietabel\/\",\"name\":\"Hoe u een contingentietabel maakt in Python\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-26T01:16:58+00:00\",\"dateModified\":\"2023-07-26T01:16:58+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u een kruistabel in Python maakt, met een stapsgewijs voorbeeld.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/python-contingentietabel\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/python-contingentietabel\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/python-contingentietabel\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe u een contingentietabel maakt in python\"}]},{\"@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 een contingentietabel maakt in Python","description":"In deze tutorial wordt uitgelegd hoe u een kruistabel in Python maakt, met een stapsgewijs voorbeeld.","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\/python-contingentietabel\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe u een contingentietabel maakt in Python","og_description":"In deze tutorial wordt uitgelegd hoe u een kruistabel in Python maakt, met een stapsgewijs voorbeeld.","og_url":"https:\/\/statorials.org\/nl\/python-contingentietabel\/","og_site_name":"Statorials","article_published_time":"2023-07-26T01:16:58+00:00","author":"Dr.benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr.benjamin anderson","Gesch\u00e4tzte Lesezeit":"3\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/nl\/python-contingentietabel\/","url":"https:\/\/statorials.org\/nl\/python-contingentietabel\/","name":"Hoe u een contingentietabel maakt in Python","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-26T01:16:58+00:00","dateModified":"2023-07-26T01:16:58+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u een kruistabel in Python maakt, met een stapsgewijs voorbeeld.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/python-contingentietabel\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/python-contingentietabel\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/python-contingentietabel\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe u een contingentietabel maakt in python"}]},{"@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\/1522","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=1522"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/1522\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=1522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=1522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=1522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}