{"id":1520,"date":"2023-07-26T01:16:58","date_gmt":"2023-07-26T01:16:58","guid":{"rendered":"https:\/\/statorials.org\/de\/python-kontingenztabelle\/"},"modified":"2023-07-26T01:16:58","modified_gmt":"2023-07-26T01:16:58","slug":"python-kontingenztabelle","status":"publish","type":"post","link":"https:\/\/statorials.org\/de\/python-kontingenztabelle\/","title":{"rendered":"So erstellen sie eine kontingenztabelle in python"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Eine <strong>Kontingenztabelle<\/strong> ist eine Art Tabelle, die die Beziehung zwischen zwei kategorialen Variablen zusammenfasst.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Um eine Kontingenztabelle in Python zu erstellen, k\u00f6nnen wir die Funktion <a href=\"https:\/\/pandas.pydata.org\/docs\/reference\/api\/pandas.crosstab.html\" target=\"_blank\" rel=\"noopener\">pandas.crossstab()<\/a> verwenden, die die folgende Syntax verwendet:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>pandas.crossstab(index, columns)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Gold:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>Index:<\/strong> Name der Variablen, die in den Zeilen der Kontingenztabelle angezeigt werden soll<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>Spalten:<\/strong> Name der Variablen, die in den Spalten der Kontingenztabelle angezeigt werden soll<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Das folgende Schritt-f\u00fcr-Schritt-Beispiel zeigt, wie Sie mit dieser Funktion eine Kontingenztabelle in Python erstellen.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Schritt 1: Erstellen Sie die Daten<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Erstellen wir zun\u00e4chst einen Datensatz, der Informationen zu 20 verschiedenen Produktbestellungen anzeigt, einschlie\u00dflich der Art des gekauften Produkts (Fernseher, Computer oder Radio) sowie des Landes (A, B oder C), in dem das Produkt gekauft wurde:<\/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;\">Schritt 2: Erstellen Sie die Kontingenztabelle<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Der folgende Code zeigt, wie Sie eine Kontingenztabelle erstellen, um die Anzahl der von jedem Land bestellten Produkte zu z\u00e4hlen:<\/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;\">So interpretieren Sie die Tabelle:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">Insgesamt wurde <strong>1<\/strong> Computer in Land A gekauft.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Insgesamt wurden <strong>3<\/strong> Computer in Land B gekauft.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Insgesamt wurden <strong>2<\/strong> Computer im Land C gekauft.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Im Land A wurden insgesamt <strong>0<\/strong> Radios gekauft.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Im Land B wurden insgesamt <strong>2<\/strong> Radios angeschafft.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Insgesamt wurden <strong>3<\/strong> Radios im Land C gekauft.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Insgesamt wurden in Land A <strong>3<\/strong> Fernseher gekauft.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Im Land B wurden insgesamt <strong>3<\/strong> Fernseher angeschafft.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Insgesamt wurden <strong>3<\/strong> Fernseher im Land C gekauft.<\/span><\/li>\n<\/ul>\n<h3> <strong><span style=\"color: #000000;\">Schritt 3: Margin-Gesamtsummen zur Kontingenztabelle hinzuf\u00fcgen<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Wir k\u00f6nnen das Argument <strong>\u201emargins=True\u201c<\/strong> verwenden, um die Margensummen zur Kontingenztabelle hinzuzuf\u00fcgen:<\/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;\">Die Interpretation der Tabellenwerte ist wie folgt:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Zeilensummen:<\/strong><\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">Insgesamt wurden <strong>4<\/strong> Bestellungen aus Land A aufgegeben.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Aus Land B wurden insgesamt <strong>8<\/strong> Bestellungen aufgegeben.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Aus Land C wurden insgesamt <strong>8<\/strong> Bestellungen aufgegeben.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\"><strong>Spaltensummen:<\/strong><\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">Insgesamt wurden <strong>6<\/strong> Computer gekauft.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Insgesamt wurden <strong>5<\/strong> Radios gekauft.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Insgesamt wurden <strong>9<\/strong> Fernseher gekauft.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Der Wert in der unteren rechten Ecke der Tabelle zeigt, dass insgesamt <strong>20<\/strong> Produkte aus allen L\u00e4ndern bestellt wurden.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Zus\u00e4tzliche Ressourcen<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/de\/kontingenztabelle-in-r\/\" target=\"_blank\" rel=\"noopener\">So erstellen Sie eine Kontingenztabelle in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/de\/excel-kontingenztabelle\/\" target=\"_blank\" rel=\"noopener\">So erstellen Sie eine Kontingenztabelle in Excel<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Eine Kontingenztabelle ist eine Art Tabelle, die die Beziehung zwischen zwei kategorialen Variablen zusammenfasst. Um eine Kontingenztabelle in Python zu erstellen, k\u00f6nnen wir die Funktion pandas.crossstab() verwenden, die die folgende Syntax verwendet: pandas.crossstab(index, columns) Gold: Index: Name der Variablen, die in den Zeilen der Kontingenztabelle angezeigt werden soll Spalten: Name der Variablen, die in den [&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":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>So erstellen Sie eine Kontingenztabelle in Python<\/title>\n<meta name=\"description\" content=\"In diesem Tutorial wird anhand eines Schritt-f\u00fcr-Schritt-Beispiels erl\u00e4utert, wie Sie eine Kontingenztabelle in Python erstellen.\" \/>\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\/de\/python-kontingenztabelle\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"So erstellen Sie eine Kontingenztabelle in Python\" \/>\n<meta property=\"og:description\" content=\"In diesem Tutorial wird anhand eines Schritt-f\u00fcr-Schritt-Beispiels erl\u00e4utert, wie Sie eine Kontingenztabelle in Python erstellen.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/de\/python-kontingenztabelle\/\" \/>\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=\"2 Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/de\/python-kontingenztabelle\/\",\"url\":\"https:\/\/statorials.org\/de\/python-kontingenztabelle\/\",\"name\":\"So erstellen Sie eine Kontingenztabelle in Python\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/de\/#website\"},\"datePublished\":\"2023-07-26T01:16:58+00:00\",\"dateModified\":\"2023-07-26T01:16:58+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0\"},\"description\":\"In diesem Tutorial wird anhand eines Schritt-f\u00fcr-Schritt-Beispiels erl\u00e4utert, wie Sie eine Kontingenztabelle in Python erstellen.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/de\/python-kontingenztabelle\/#breadcrumb\"},\"inLanguage\":\"de-DE\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/de\/python-kontingenztabelle\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/de\/python-kontingenztabelle\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Heim\",\"item\":\"https:\/\/statorials.org\/de\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"So erstellen sie eine kontingenztabelle in python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/de\/#website\",\"url\":\"https:\/\/statorials.org\/de\/\",\"name\":\"Statorials\",\"description\":\"Ihr Leitfaden f\u00fcr statistische Kompetenz !\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/de\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"de-DE\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0\",\"name\":\"Dr. Benjamin Anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de-DE\",\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr. Benjamin Anderson\"},\"description\":\"Hallo, ich bin Benjamin, ein pensionierter Statistikprofessor, der sich zum engagierten Statorials-Lehrer entwickelt hat. Mit umfassender Erfahrung und Fachwissen auf dem Gebiet der Statistik bin ich bestrebt, mein Wissen zu teilen, um Studenten durch Statorials zu bef\u00e4higen. Mehr wissen\",\"sameAs\":[\"https:\/\/statorials.org\/de\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"So erstellen Sie eine Kontingenztabelle in Python","description":"In diesem Tutorial wird anhand eines Schritt-f\u00fcr-Schritt-Beispiels erl\u00e4utert, wie Sie eine Kontingenztabelle in Python erstellen.","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\/de\/python-kontingenztabelle\/","og_locale":"de_DE","og_type":"article","og_title":"So erstellen Sie eine Kontingenztabelle in Python","og_description":"In diesem Tutorial wird anhand eines Schritt-f\u00fcr-Schritt-Beispiels erl\u00e4utert, wie Sie eine Kontingenztabelle in Python erstellen.","og_url":"https:\/\/statorials.org\/de\/python-kontingenztabelle\/","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":"2 Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/de\/python-kontingenztabelle\/","url":"https:\/\/statorials.org\/de\/python-kontingenztabelle\/","name":"So erstellen Sie eine Kontingenztabelle in Python","isPartOf":{"@id":"https:\/\/statorials.org\/de\/#website"},"datePublished":"2023-07-26T01:16:58+00:00","dateModified":"2023-07-26T01:16:58+00:00","author":{"@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0"},"description":"In diesem Tutorial wird anhand eines Schritt-f\u00fcr-Schritt-Beispiels erl\u00e4utert, wie Sie eine Kontingenztabelle in Python erstellen.","breadcrumb":{"@id":"https:\/\/statorials.org\/de\/python-kontingenztabelle\/#breadcrumb"},"inLanguage":"de-DE","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/de\/python-kontingenztabelle\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/de\/python-kontingenztabelle\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Heim","item":"https:\/\/statorials.org\/de\/"},{"@type":"ListItem","position":2,"name":"So erstellen sie eine kontingenztabelle in python"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/de\/#website","url":"https:\/\/statorials.org\/de\/","name":"Statorials","description":"Ihr Leitfaden f\u00fcr statistische Kompetenz !","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/de\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"de-DE"},{"@type":"Person","@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0","name":"Dr. Benjamin Anderson","image":{"@type":"ImageObject","inLanguage":"de-DE","@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg","caption":"Dr. Benjamin Anderson"},"description":"Hallo, ich bin Benjamin, ein pensionierter Statistikprofessor, der sich zum engagierten Statorials-Lehrer entwickelt hat. Mit umfassender Erfahrung und Fachwissen auf dem Gebiet der Statistik bin ich bestrebt, mein Wissen zu teilen, um Studenten durch Statorials zu bef\u00e4higen. Mehr wissen","sameAs":["https:\/\/statorials.org\/de"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts\/1520"}],"collection":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/comments?post=1520"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts\/1520\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/media?parent=1520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/categories?post=1520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/tags?post=1520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}