{"id":3122,"date":"2023-07-19T02:44:58","date_gmt":"2023-07-19T02:44:58","guid":{"rendered":"https:\/\/statorials.org\/de\/pandas-pivot-tabelle-ersetzen-sie-nan-durch-0\/"},"modified":"2023-07-19T02:44:58","modified_gmt":"2023-07-19T02:44:58","slug":"pandas-pivot-tabelle-ersetzen-sie-nan-durch-0","status":"publish","type":"post","link":"https:\/\/statorials.org\/de\/pandas-pivot-tabelle-ersetzen-sie-nan-durch-0\/","title":{"rendered":"Pandas: so ersetzen sie nan-werte in der pivot-tabelle durch nullen"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Sie k\u00f6nnen das Argument <strong>fill_value<\/strong> in Pandas verwenden, um NaN-Werte in einer Pivot-Tabelle durch Nullen zu ersetzen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Dazu k\u00f6nnen Sie die folgende grundlegende Syntax verwenden:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>p.d. <span style=\"color: #3366ff;\">pivot_table<\/span> (df, values=' <span style=\"color: #ff0000;\">col1<\/span> ', index=' <span style=\"color: #ff0000;\">col2<\/span> ', columns=' <span style=\"color: #ff0000;\">col3<\/span> ', fill_value= <span style=\"color: #008000;\">0<\/span> )\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Das folgende Beispiel zeigt, wie diese Syntax in der Praxis verwendet wird.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Beispiel: Ersetzen Sie NaN-Werte in der Pivot-Tabelle durch Nullen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Angenommen, wir haben den folgenden Pandas-DataFrame, der Informationen \u00fcber verschiedene Basketballspieler enth\u00e4lt:<\/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', 'B', 'B', 'B', 'B'],\n                   ' <span style=\"color: #ff0000;\">position<\/span> ': ['G', 'G', 'F', 'C', 'F', 'F', 'F', 'F'],\n                   ' <span style=\"color: #ff0000;\">points<\/span> ': [4, 4, 6, 8, 9, 5, 5, 12]})\n\n<span style=\"color: #008080;\">#view DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n\tteam position points\n0 A G 4\n1 A G 4\n2 A F 6\n3 A C 8\n4 B F 9\n5 B F 5\n6 B F 5\n7 B F 12<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Mit dem folgenden Code k\u00f6nnen wir in Pandas eine Pivot-Tabelle erstellen, die den durchschnittlichen <strong>Punktwert<\/strong> f\u00fcr jedes <strong>Team<\/strong> und <strong>jede Position<\/strong> im DataFrame anzeigt:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#create pivot table\n<\/span>df_pivot = pd. <span style=\"color: #3366ff;\">pivot_table<\/span> (df, values=' <span style=\"color: #ff0000;\">points<\/span> ', index=' <span style=\"color: #ff0000;\">team<\/span> ', columns=' <span style=\"color: #ff0000;\">position<\/span> ')\n\n<span style=\"color: #008080;\">#view pivot table\n<\/span><span style=\"color: #008000;\">print<\/span> (df_pivot)\n\nCFG position\nteam                    \nA 8.0 6.00 4.0\nB NaN 7.75 NaN<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Beachten Sie, dass die Pivot-Tabelle zwei NaN-Werte enth\u00e4lt, da im urspr\u00fcnglichen DataFrame kein Spieler eine <strong>C-<\/strong> oder <strong>G-<\/strong> Position in Team B hat, sodass diese beiden Positionen NaN-Werte in der Pivot-Tabelle haben.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Um diese NaN-Werte in der Pivot-Tabelle mit Nullen zu f\u00fcllen, k\u00f6nnen wir das Argument <strong>fill_value<\/strong> verwenden:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#create pivot table with zeros instead of NaN values\n<\/span>df_pivot = pd. <span style=\"color: #3366ff;\">pivot_table<\/span> (df, values=' <span style=\"color: #ff0000;\">points<\/span> ', index=' <span style=\"color: #ff0000;\">team<\/span> ', columns=' <span style=\"color: #ff0000;\">position<\/span> ',\n                          fill_value= <span style=\"color: #008000;\">0<\/span> )\n\n<span style=\"color: #008080;\">#view pivot table\n<\/span><span style=\"color: #008000;\">print<\/span> (df_pivot)\n\nCFG position\nteam                \nA 8 6.00 4\nB 0 7.75 0<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Beachten Sie, dass jeder der NaN-Werte in der vorherigen Pivot-Tabelle mit Nullen aufgef\u00fcllt wurde.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Hinweis<\/strong> : Die vollst\u00e4ndige Dokumentation der Pandas- <strong>Pivot_table()<\/strong> -Funktion finden Sie <a href=\"https:\/\/pandas.pydata.org\/docs\/reference\/api\/pandas.pivot_table.html\" target=\"_blank\" rel=\"noopener\">hier<\/a> .<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Zus\u00e4tzliche Ressourcen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">In den folgenden Tutorials wird erl\u00e4utert, wie andere g\u00e4ngige Vorg\u00e4nge in Pandas ausgef\u00fchrt werden:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/de\/lange-bis-breite-pandas\/\" target=\"_blank\" rel=\"noopener\">Pandas: So formen Sie den DataFrame von lang zu breit um<\/a><br \/> <a href=\"https:\/\/statorials.org\/de\/breite-bis-lange-pandas\/\" target=\"_blank\" rel=\"noopener\">Pandas: So formen Sie den DataFrame von breit nach lang um<\/a><br \/> <a href=\"https:\/\/statorials.org\/de\/pandas-groupby-aggregiert-mehrere-spalten\/\" target=\"_blank\" rel=\"noopener\">Pandas: So gruppieren und aggregieren Sie \u00fcber mehrere Spalten hinweg<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sie k\u00f6nnen das Argument fill_value in Pandas verwenden, um NaN-Werte in einer Pivot-Tabelle durch Nullen zu ersetzen. Dazu k\u00f6nnen Sie die folgende grundlegende Syntax verwenden: p.d. pivot_table (df, values=&#8216; col1 &#8218;, index=&#8216; col2 &#8218;, columns=&#8216; col3 &#8218;, fill_value= 0 ) Das folgende Beispiel zeigt, wie diese Syntax in der Praxis verwendet wird. Beispiel: Ersetzen Sie [&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>Pandas: So ersetzen Sie NaN-Werte in der Pivot-Tabelle durch Nullen \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"In diesem Tutorial wird anhand eines Beispiels erkl\u00e4rt, wie man NaN-Werte in einer Pivot-Tabelle in Pandas durch Null ersetzt.\" \/>\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\/pandas-pivot-tabelle-ersetzen-sie-nan-durch-0\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pandas: So ersetzen Sie NaN-Werte in der Pivot-Tabelle durch Nullen \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"In diesem Tutorial wird anhand eines Beispiels erkl\u00e4rt, wie man NaN-Werte in einer Pivot-Tabelle in Pandas durch Null ersetzt.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/de\/pandas-pivot-tabelle-ersetzen-sie-nan-durch-0\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-19T02:44: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\/pandas-pivot-tabelle-ersetzen-sie-nan-durch-0\/\",\"url\":\"https:\/\/statorials.org\/de\/pandas-pivot-tabelle-ersetzen-sie-nan-durch-0\/\",\"name\":\"Pandas: So ersetzen Sie NaN-Werte in der Pivot-Tabelle durch Nullen \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/de\/#website\"},\"datePublished\":\"2023-07-19T02:44:58+00:00\",\"dateModified\":\"2023-07-19T02:44:58+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0\"},\"description\":\"In diesem Tutorial wird anhand eines Beispiels erkl\u00e4rt, wie man NaN-Werte in einer Pivot-Tabelle in Pandas durch Null ersetzt.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/de\/pandas-pivot-tabelle-ersetzen-sie-nan-durch-0\/#breadcrumb\"},\"inLanguage\":\"de-DE\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/de\/pandas-pivot-tabelle-ersetzen-sie-nan-durch-0\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/de\/pandas-pivot-tabelle-ersetzen-sie-nan-durch-0\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Heim\",\"item\":\"https:\/\/statorials.org\/de\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Pandas: so ersetzen sie nan-werte in der pivot-tabelle durch nullen\"}]},{\"@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":"Pandas: So ersetzen Sie NaN-Werte in der Pivot-Tabelle durch Nullen \u2013 Statorials","description":"In diesem Tutorial wird anhand eines Beispiels erkl\u00e4rt, wie man NaN-Werte in einer Pivot-Tabelle in Pandas durch Null ersetzt.","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\/pandas-pivot-tabelle-ersetzen-sie-nan-durch-0\/","og_locale":"de_DE","og_type":"article","og_title":"Pandas: So ersetzen Sie NaN-Werte in der Pivot-Tabelle durch Nullen \u2013 Statorials","og_description":"In diesem Tutorial wird anhand eines Beispiels erkl\u00e4rt, wie man NaN-Werte in einer Pivot-Tabelle in Pandas durch Null ersetzt.","og_url":"https:\/\/statorials.org\/de\/pandas-pivot-tabelle-ersetzen-sie-nan-durch-0\/","og_site_name":"Statorials","article_published_time":"2023-07-19T02:44: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\/pandas-pivot-tabelle-ersetzen-sie-nan-durch-0\/","url":"https:\/\/statorials.org\/de\/pandas-pivot-tabelle-ersetzen-sie-nan-durch-0\/","name":"Pandas: So ersetzen Sie NaN-Werte in der Pivot-Tabelle durch Nullen \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/de\/#website"},"datePublished":"2023-07-19T02:44:58+00:00","dateModified":"2023-07-19T02:44:58+00:00","author":{"@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0"},"description":"In diesem Tutorial wird anhand eines Beispiels erkl\u00e4rt, wie man NaN-Werte in einer Pivot-Tabelle in Pandas durch Null ersetzt.","breadcrumb":{"@id":"https:\/\/statorials.org\/de\/pandas-pivot-tabelle-ersetzen-sie-nan-durch-0\/#breadcrumb"},"inLanguage":"de-DE","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/de\/pandas-pivot-tabelle-ersetzen-sie-nan-durch-0\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/de\/pandas-pivot-tabelle-ersetzen-sie-nan-durch-0\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Heim","item":"https:\/\/statorials.org\/de\/"},{"@type":"ListItem","position":2,"name":"Pandas: so ersetzen sie nan-werte in der pivot-tabelle durch nullen"}]},{"@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\/3122"}],"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=3122"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts\/3122\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/media?parent=3122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/categories?post=3122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/tags?post=3122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}