{"id":3780,"date":"2023-07-15T14:29:24","date_gmt":"2023-07-15T14:29:24","guid":{"rendered":"https:\/\/statorials.org\/id\/tabel-pivot-pandas-menghapus-multiindex\/"},"modified":"2023-07-15T14:29:24","modified_gmt":"2023-07-15T14:29:24","slug":"tabel-pivot-pandas-menghapus-multiindex","status":"publish","type":"post","link":"https:\/\/statorials.org\/id\/tabel-pivot-pandas-menghapus-multiindex\/","title":{"rendered":"Pandas: cara menghapus multiindex di tabel pivot"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Untuk menghapus multiIndex dari tabel pivot pandas, Anda dapat menggunakan argumen <strong>nilai<\/strong> dengan fungsi <strong>reset_index()<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>p.d. <span style=\"color: #3366ff;\">pivot_table<\/span> (df, index=' <span style=\"color: #ff0000;\">col1<\/span> ', columns=' <span style=\"color: #ff0000;\">col2<\/span> ', values=' <span style=\"color: #ff0000;\">col3<\/span> '). <span style=\"color: #3366ff;\">reset_index<\/span> ()\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Contoh berikut menunjukkan cara menggunakan sintaksis ini dalam praktiknya.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Contoh: Hapus MultiIndex di Pandas PivotTable<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Misalkan kita memiliki pandas DataFrame berikut yang berisi informasi tentang berbagai pemain bola basket:<\/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', 'F', 'G', '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  team position points\n0 AG 4\n1 GA 4\n2 AF 6\n3AF 8\n4 BG 9\n5 BF 5\n6 BF 5\n7 BF 12<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Sekarang anggaplah kita membuat tabel pivot berikut untuk merangkum nilai rata-rata <strong>poin<\/strong> berdasarkan <strong>tim<\/strong> dan <strong>posisi<\/strong> :<\/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 to summarize mean points by team and position\n<\/span>p.d. <span style=\"color: #3366ff;\">pivot_table<\/span> (df, index=' <span style=\"color: #ff0000;\">team<\/span> ', columns=' <span style=\"color: #ff0000;\">position<\/span> ')\n\n\t        points\nFG position\nteam\t\t\nAt 7.000000 4.0\nB 7.333333 9.0\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tabel pivot yang dihasilkan merangkum nilai <strong>poin<\/strong> rata-rata berdasarkan <strong>team<\/strong> dan <strong>position<\/strong> , namun berisi multiIndex.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Untuk menghapus multiIndex, kita dapat menggunakan argumen <strong>nilai<\/strong> di fungsi <strong>pivot_table()<\/strong> dan menambahkan <strong>reset_index()<\/strong> di akhir:<\/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 to summarize mean points by team and position\n<\/span>p.d. <span style=\"color: #3366ff;\">pivot_table<\/span> (df, index=' <span style=\"color: #ff0000;\">team<\/span> ', columns=' <span style=\"color: #ff0000;\">position<\/span> ', values=' <span style=\"color: #ff0000;\">points<\/span> '). <span style=\"color: #3366ff;\">reset_index<\/span> ()\n\nposition team F G\n0 to 7.000000 4.0\n1 B 7.333333 9.0\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">Tabel pivot yang dihasilkan merangkum nilai <strong>poin<\/strong> rata-rata berdasarkan <strong>tim<\/strong> dan <strong>posisi<\/strong> dan tidak lagi memiliki multiIndex.<\/span><\/span><\/p>\n<p> <span style=\"color: #000000;\">Perhatikan bahwa fungsi <strong>pivot_table()<\/strong> menghitung nilai rata-rata secara default.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Untuk menghitung metrik lain, seperti jumlah, gunakan argumen <strong>aggfunc<\/strong> sebagai berikut:<\/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 to summarize sum of points by team and position\n<\/span>p.d. <span style=\"color: #3366ff;\">pivot_table<\/span> (df, index=' <span style=\"color: #ff0000;\">team<\/span> ', columns=' <span style=\"color: #ff0000;\">position<\/span> ', values=' <span style=\"color: #ff0000;\">points<\/span> ',\n               aggfunc=' <span style=\"color: #ff0000;\">sum<\/span> '). <span style=\"color: #3366ff;\">reset_index<\/span> ()\n\nposition team FG\n0 to 14 8\n1 B 22 9<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tabel pivot yang dihasilkan merangkum jumlah nilai <strong>poin<\/strong> berdasarkan <strong>tim<\/strong> dan <strong>posisi<\/strong> dan juga tidak memiliki multiIndex.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Catatan<\/strong> : Anda dapat menemukan dokumentasi lengkap fungsi pandas <strong>pivot_table()<\/strong> <a href=\"https:\/\/pandas.pydata.org\/docs\/reference\/api\/pandas.pivot_table.html\" target=\"_blank\" rel=\"noopener\">di sini<\/a> .<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Sumber daya tambahan<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Tutorial berikut menjelaskan cara melakukan operasi umum lainnya di panda:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/id\/filter-tabel-pivot-panda\/\" target=\"_blank\" rel=\"noopener\">Pandas: Cara menambahkan filter ke tabel pivot<\/a><br \/> <a href=\"https:\/\/statorials.org\/id\/mantra-tabel-pivot-panda\/\" target=\"_blank\" rel=\"noopener\">Pandas: Cara mengurutkan tabel pivot berdasarkan nilai di kolom<\/a><br \/> <a href=\"https:\/\/statorials.org\/id\/tabel-pivot-panda-di-bawah-total\/\" target=\"_blank\" rel=\"noopener\">Pandas: Cara menambahkan subtotal ke tabel pivot<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Untuk menghapus multiIndex dari tabel pivot pandas, Anda dapat menggunakan argumen nilai dengan fungsi reset_index() : p.d. pivot_table (df, index=&#8217; col1 &#8216;, columns=&#8217; col2 &#8216;, values=&#8217; col3 &#8216;). reset_index () Contoh berikut menunjukkan cara menggunakan sintaksis ini dalam praktiknya. Contoh: Hapus MultiIndex di Pandas PivotTable Misalkan kita memiliki pandas DataFrame berikut yang berisi informasi tentang [&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: Cara Menghapus MultiIndex di Tabel Pivot - Statologi<\/title>\n<meta name=\"description\" content=\"Tutorial ini menjelaskan cara menghapus multiIndex dari tabel pivot pandas, dengan sebuah contoh.\" \/>\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\/id\/tabel-pivot-pandas-menghapus-multiindex\/\" \/>\n<meta property=\"og:locale\" content=\"id_ID\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pandas: Cara Menghapus MultiIndex di Tabel Pivot - Statologi\" \/>\n<meta property=\"og:description\" content=\"Tutorial ini menjelaskan cara menghapus multiIndex dari tabel pivot pandas, dengan sebuah contoh.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/id\/tabel-pivot-pandas-menghapus-multiindex\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-15T14:29:24+00:00\" \/>\n<meta name=\"author\" content=\"Benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Ditulis oleh\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimasi waktu membaca\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 menit\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/id\/tabel-pivot-pandas-menghapus-multiindex\/\",\"url\":\"https:\/\/statorials.org\/id\/tabel-pivot-pandas-menghapus-multiindex\/\",\"name\":\"Pandas: Cara Menghapus MultiIndex di Tabel Pivot - Statologi\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/id\/#website\"},\"datePublished\":\"2023-07-15T14:29:24+00:00\",\"dateModified\":\"2023-07-15T14:29:24+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/id\/#\/schema\/person\/3d17a1160dd2d052b7c78e502cb9ec81\"},\"description\":\"Tutorial ini menjelaskan cara menghapus multiIndex dari tabel pivot pandas, dengan sebuah contoh.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/id\/tabel-pivot-pandas-menghapus-multiindex\/#breadcrumb\"},\"inLanguage\":\"id\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/id\/tabel-pivot-pandas-menghapus-multiindex\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/id\/tabel-pivot-pandas-menghapus-multiindex\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/statorials.org\/id\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Pandas: cara menghapus multiindex di tabel pivot\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/id\/#website\",\"url\":\"https:\/\/statorials.org\/id\/\",\"name\":\"Statorials\",\"description\":\"Panduan anda untuk kompetensi statistik!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/id\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"id\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/id\/#\/schema\/person\/3d17a1160dd2d052b7c78e502cb9ec81\",\"name\":\"Benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"id\",\"@id\":\"https:\/\/statorials.org\/id\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/statorials.org\/id\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"http:\/\/statorials.org\/id\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin anderson\"},\"description\":\"Halo, saya Benjamin, pensiunan profesor statistika yang menjadi guru Statorial yang berdedikasi. Dengan pengalaman dan keahlian yang luas di bidang statistika, saya ingin berbagi ilmu untuk memberdayakan mahasiswa melalui Statorials. Baca selengkapnya\",\"sameAs\":[\"http:\/\/statorials.org\/id\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Pandas: Cara Menghapus MultiIndex di Tabel Pivot - Statologi","description":"Tutorial ini menjelaskan cara menghapus multiIndex dari tabel pivot pandas, dengan sebuah contoh.","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\/id\/tabel-pivot-pandas-menghapus-multiindex\/","og_locale":"id_ID","og_type":"article","og_title":"Pandas: Cara Menghapus MultiIndex di Tabel Pivot - Statologi","og_description":"Tutorial ini menjelaskan cara menghapus multiIndex dari tabel pivot pandas, dengan sebuah contoh.","og_url":"https:\/\/statorials.org\/id\/tabel-pivot-pandas-menghapus-multiindex\/","og_site_name":"Statorials","article_published_time":"2023-07-15T14:29:24+00:00","author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Ditulis oleh":"Benjamin anderson","Estimasi waktu membaca":"2 menit"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/id\/tabel-pivot-pandas-menghapus-multiindex\/","url":"https:\/\/statorials.org\/id\/tabel-pivot-pandas-menghapus-multiindex\/","name":"Pandas: Cara Menghapus MultiIndex di Tabel Pivot - Statologi","isPartOf":{"@id":"https:\/\/statorials.org\/id\/#website"},"datePublished":"2023-07-15T14:29:24+00:00","dateModified":"2023-07-15T14:29:24+00:00","author":{"@id":"https:\/\/statorials.org\/id\/#\/schema\/person\/3d17a1160dd2d052b7c78e502cb9ec81"},"description":"Tutorial ini menjelaskan cara menghapus multiIndex dari tabel pivot pandas, dengan sebuah contoh.","breadcrumb":{"@id":"https:\/\/statorials.org\/id\/tabel-pivot-pandas-menghapus-multiindex\/#breadcrumb"},"inLanguage":"id","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/id\/tabel-pivot-pandas-menghapus-multiindex\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/id\/tabel-pivot-pandas-menghapus-multiindex\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/statorials.org\/id\/"},{"@type":"ListItem","position":2,"name":"Pandas: cara menghapus multiindex di tabel pivot"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/id\/#website","url":"https:\/\/statorials.org\/id\/","name":"Statorials","description":"Panduan anda untuk kompetensi statistik!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/id\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"id"},{"@type":"Person","@id":"https:\/\/statorials.org\/id\/#\/schema\/person\/3d17a1160dd2d052b7c78e502cb9ec81","name":"Benjamin anderson","image":{"@type":"ImageObject","inLanguage":"id","@id":"https:\/\/statorials.org\/id\/#\/schema\/person\/image\/","url":"http:\/\/statorials.org\/id\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"http:\/\/statorials.org\/id\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Benjamin anderson"},"description":"Halo, saya Benjamin, pensiunan profesor statistika yang menjadi guru Statorial yang berdedikasi. Dengan pengalaman dan keahlian yang luas di bidang statistika, saya ingin berbagi ilmu untuk memberdayakan mahasiswa melalui Statorials. Baca selengkapnya","sameAs":["http:\/\/statorials.org\/id"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/id\/wp-json\/wp\/v2\/posts\/3780"}],"collection":[{"href":"https:\/\/statorials.org\/id\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/id\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/id\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/id\/wp-json\/wp\/v2\/comments?post=3780"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/id\/wp-json\/wp\/v2\/posts\/3780\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/id\/wp-json\/wp\/v2\/media?parent=3780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/id\/wp-json\/wp\/v2\/categories?post=3780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/id\/wp-json\/wp\/v2\/tags?post=3780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}