{"id":3767,"date":"2023-07-15T16:23:22","date_gmt":"2023-07-15T16:23:22","guid":{"rendered":"https:\/\/statorials.org\/it\/panda-groupby-ottieni-gruppo\/"},"modified":"2023-07-15T16:23:22","modified_gmt":"2023-07-15T16:23:22","slug":"panda-groupby-ottieni-gruppo","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/panda-groupby-ottieni-gruppo\/","title":{"rendered":"Panda: come ottenere un gruppo dopo aver utilizzato groupby()"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare i seguenti metodi per ottenere un gruppo specifico dopo aver utilizzato la funzione <strong>groupby()<\/strong> su un DataFrame panda:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: ottieni il gruppo dopo aver utilizzato groupby()<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>grouped_df. <span style=\"color: #3366ff;\">get_group<\/span> (' <span style=\"color: #ff0000;\">A<\/span> ')\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: ottieni colonne specifiche dal gruppo dopo aver utilizzato groupby()<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>grouped_df[[' <span style=\"color: #ff0000;\">column1<\/span> ', ' <span style=\"color: #ff0000;\">column3<\/span> ']]. <span style=\"color: #3366ff;\">get_group<\/span> (' <span style=\"color: #ff0000;\">A<\/span> ')<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">I seguenti esempi mostrano come utilizzare ciascun metodo nella pratica con i seguenti DataFrame panda:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <b><span style=\"color: #008000;\">import<\/span> pandas <span style=\"color: #008000;\">as<\/span> pd\n\n<span style=\"color: #008080;\">#createDataFrame<\/span>\ndf = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">store<\/span> ': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B'],\n                   ' <span style=\"color: #ff0000;\">sales<\/span> ': [12, 15, 24, 24, 14, 19, 12, 38],\n                   ' <span style=\"color: #ff0000;\">refunds<\/span> ': [4, 8, 7, 7, 10, 5, 4, 11]})\n\n<span style=\"color: #008080;\">#view DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n  store sales refunds\n0 to 12 4\n1 to 15 8\n2 to 24 7\n3 to 24 7\n4 B 14 10\n5 B 19 5\n6 B 12 4\n7 B 38 11<\/b><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 1: ottieni un gruppo dopo aver utilizzato groupby()<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come utilizzare la funzione <strong>groupby(<\/strong> ) per raggruppare le righe in base al nome del negozio, quindi utilizzare la funzione <strong>get_group()<\/strong> per recuperare tutte le righe appartenenti al gruppo con nome gruppo &#8220;A&#8221;:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#group rows of DataFrame based on value in 'store' column\n<span style=\"color: #000000;\">grouped_stores = df. <span style=\"color: #3366ff;\">groupby<\/span> ([' <span style=\"color: #ff0000;\">store<\/span> '])\n\n<span style=\"color: #008080;\">#get all rows that belong to group name 'A'\n<\/span>grouped_stores. <span style=\"color: #3366ff;\">get_group<\/span> (' <span style=\"color: #ff0000;\">A<\/span> ')\n\n    store sales refunds\n0 to 12 4\n1 to 15 8\n2 to 24 7\n3 to 24 7\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">Tieni presente che <strong>get_group()<\/strong> restituisce tutte le righe appartenenti al gruppo con il nome del gruppo &#8220;A&#8221;.<\/span><\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 2: ottieni colonne specifiche dal gruppo dopo aver utilizzato groupby()<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come utilizzare la funzione <strong>groupby(<\/strong> ) per raggruppare le righe in base al nome del negozio, quindi utilizzare la funzione <strong>get_group()<\/strong> per recuperare tutte le righe appartenenti al gruppo con nome gruppo &#8220;A&#8221; solo per le colonne &#8220;vendite&#8221; e &#8220;Rimborsi&#8221; :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#group rows of DataFrame based on value in 'store' column\n<span style=\"color: #000000;\">grouped_stores = df. <span style=\"color: #3366ff;\">groupby<\/span> ([' <span style=\"color: #ff0000;\">store<\/span> '])\n\n<span style=\"color: #008080;\">#get all rows that belong to group name 'A' for sales and refunds columns\n<\/span>grouped_stores[[' <span style=\"color: #ff0000;\">store<\/span> ', ' <span style=\"color: #ff0000;\">refunds<\/span> ']]. <span style=\"color: #3366ff;\">get_group<\/span> (' <span style=\"color: #ff0000;\">A<\/span> ')\n\n    store refunds\n0 to 4\n1 to 8\n2 to 7\n3 to 7\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che <strong>get_group()<\/strong> restituisce tutte le righe appartenenti al gruppo con nome gruppo &#8220;A&#8221; solo per le colonne &#8220;vendite&#8221; e &#8220;rimborsi&#8221;.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">I seguenti tutorial spiegano come eseguire altre operazioni comuni nei panda:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/gruppo-di-panda-per-somma\/\" target=\"_blank\" rel=\"noopener\">Come eseguire una somma GroupBy in Pandas<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/gruppo-di-panda-per-trama\/\" target=\"_blank\" rel=\"noopener\">Come utilizzare Groupby e Plot in Pandas<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/panda-groupby-conta-unico\/\" target=\"_blank\" rel=\"noopener\">Come contare valori univoci utilizzando GroupBy in Pandas<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare i seguenti metodi per ottenere un gruppo specifico dopo aver utilizzato la funzione groupby() su un DataFrame panda: Metodo 1: ottieni il gruppo dopo aver utilizzato groupby() grouped_df. get_group (&#8216; A &#8216;) Metodo 2: ottieni colonne specifiche dal gruppo dopo aver utilizzato groupby() grouped_df[[&#8216; column1 &#8216;, &#8216; column3 &#8216;]]. get_group (&#8216; A [&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>Panda: come ottenere un gruppo dopo aver utilizzato groupby() \u2013 Stology<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come ottenere un gruppo specifico dopo aver utilizzato la funzione groupby() su un DataFrame panda, inclusi esempi.\" \/>\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\/it\/panda-groupby-ottieni-gruppo\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Panda: come ottenere un gruppo dopo aver utilizzato groupby() \u2013 Stology\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come ottenere un gruppo specifico dopo aver utilizzato la funzione groupby() su un DataFrame panda, inclusi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/panda-groupby-ottieni-gruppo\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-15T16:23:22+00:00\" \/>\n<meta name=\"author\" content=\"Benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/panda-groupby-ottieni-gruppo\/\",\"url\":\"https:\/\/statorials.org\/it\/panda-groupby-ottieni-gruppo\/\",\"name\":\"Panda: come ottenere un gruppo dopo aver utilizzato groupby() \u2013 Stology\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-15T16:23:22+00:00\",\"dateModified\":\"2023-07-15T16:23:22+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come ottenere un gruppo specifico dopo aver utilizzato la funzione groupby() su un DataFrame panda, inclusi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/panda-groupby-ottieni-gruppo\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/panda-groupby-ottieni-gruppo\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/panda-groupby-ottieni-gruppo\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Panda: come ottenere un gruppo dopo aver utilizzato groupby()\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/it\/#website\",\"url\":\"https:\/\/statorials.org\/it\/\",\"name\":\"Statorials\",\"description\":\"La tua guida all&#039;alfabetizzazione statistica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/it\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\",\"name\":\"Benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin anderson\"},\"description\":\"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9\",\"sameAs\":[\"https:\/\/statorials.org\/it\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Panda: come ottenere un gruppo dopo aver utilizzato groupby() \u2013 Stology","description":"Questo tutorial spiega come ottenere un gruppo specifico dopo aver utilizzato la funzione groupby() su un DataFrame panda, inclusi esempi.","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\/it\/panda-groupby-ottieni-gruppo\/","og_locale":"it_IT","og_type":"article","og_title":"Panda: come ottenere un gruppo dopo aver utilizzato groupby() \u2013 Stology","og_description":"Questo tutorial spiega come ottenere un gruppo specifico dopo aver utilizzato la funzione groupby() su un DataFrame panda, inclusi esempi.","og_url":"https:\/\/statorials.org\/it\/panda-groupby-ottieni-gruppo\/","og_site_name":"Statorials","article_published_time":"2023-07-15T16:23:22+00:00","author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"2 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/panda-groupby-ottieni-gruppo\/","url":"https:\/\/statorials.org\/it\/panda-groupby-ottieni-gruppo\/","name":"Panda: come ottenere un gruppo dopo aver utilizzato groupby() \u2013 Stology","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-15T16:23:22+00:00","dateModified":"2023-07-15T16:23:22+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come ottenere un gruppo specifico dopo aver utilizzato la funzione groupby() su un DataFrame panda, inclusi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/panda-groupby-ottieni-gruppo\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/panda-groupby-ottieni-gruppo\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/panda-groupby-ottieni-gruppo\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Panda: come ottenere un gruppo dopo aver utilizzato groupby()"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/it\/#website","url":"https:\/\/statorials.org\/it\/","name":"Statorials","description":"La tua guida all&#039;alfabetizzazione statistica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/it\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae","name":"Benjamin anderson","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Benjamin anderson"},"description":"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9","sameAs":["https:\/\/statorials.org\/it"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3767"}],"collection":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/comments?post=3767"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3767\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}