{"id":2921,"date":"2023-07-20T02:21:24","date_gmt":"2023-07-20T02:21:24","guid":{"rendered":"https:\/\/statorials.org\/it\/i-panda-raggruppano-per-concatenare-stringhe\/"},"modified":"2023-07-20T02:21:24","modified_gmt":"2023-07-20T02:21:24","slug":"i-panda-raggruppano-per-concatenare-stringhe","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/i-panda-raggruppano-per-concatenare-stringhe\/","title":{"rendered":"Panda: come concatenare stringhe utilizzando groupby"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare la seguente sintassi di base per concatenare stringhe da GroupBy in panda:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>df. <span style=\"color: #3366ff;\">groupby<\/span> ([' <span style=\"color: #ff0000;\">group_var<\/span> '], as_index= <span style=\"color: #008000;\">False<\/span> ). <span style=\"color: #3366ff;\">agg<\/span> ({' <span style=\"color: #ff0000;\">string_var<\/span> ': ' ' <span style=\"color: #3366ff;\">.join<\/span> })\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questa particolare formula raggruppa le righe in base alla colonna <strong>group_var<\/strong> , quindi concatena le stringhe nella colonna <strong>string_var<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">L&#8217;esempio seguente mostra come utilizzare questa sintassi nella pratica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio: come concatenare stringhe utilizzando GroupBy<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di avere i seguenti panda DataFrame:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><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;\">quarter<\/span> ': [1, 1, 2, 2, 1, 1, 2, 2],\n                   ' <span style=\"color: #ff0000;\">employee<\/span> ': ['Andy', 'Bob', 'Chad', 'Diane',\n                                'Elana', 'Frank', 'George', 'Hank']})\n\n<span style=\"color: #008080;\">#view DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare la seguente sintassi per raggruppare le righe del DataFrame per <strong>negozio<\/strong> e <strong>trimestre<\/strong> e poi concatenare le stringhe nella colonna <strong>Employee<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#group by store and quarter, then concatenate employee strings\n<span style=\"color: #000000;\">df. <span style=\"color: #3366ff;\">groupby<\/span> ([' <span style=\"color: #ff0000;\">store<\/span> ', ' <span style=\"color: #ff0000;\">quarter<\/span> '], as_index= <span style=\"color: #008000;\">False<\/span> ). <span style=\"color: #3366ff;\">agg<\/span> ({' <span style=\"color: #ff0000;\">employee<\/span> ':''. <span style=\"color: #3366ff;\">join<\/span> })\n\n\tstore quarter employee\n0 To 1 Andy Bob\n1 A 2 Chad Diane\n2 B 1 Elana Frank\n3 B 2 George Hank<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Il risultato \u00e8 un DataFrame raggruppato per <strong>negozio<\/strong> e <strong>trimestre<\/strong> con le stringhe della colonna <strong>dei dipendenti<\/strong> concatenate con uno spazio.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Potremmo anche concatenare le stringhe utilizzando un separatore diverso come il simbolo <strong>&amp;<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#group by store and quarter, then concatenate employee strings\n<span style=\"color: #000000;\">df. <span style=\"color: #3366ff;\">groupby<\/span> ([' <span style=\"color: #ff0000;\">store<\/span> ', ' <span style=\"color: #ff0000;\">quarter<\/span> '], as_index= <span style=\"color: #008000;\">False<\/span> ). <span style=\"color: #3366ff;\">agg<\/span> ({' <span style=\"color: #ff0000;\">employee<\/span> ':' <span style=\"color: #ff0000;\">&amp;<\/span> '. <span style=\"color: #3366ff;\">join<\/span> })\n\n\tstore quarter employee\n0 To 1 Andy &amp; Bob\n1 A 2 Chad &amp; Diane\n2 B 1 Elana &amp; Frank\n3 B 2 George &amp; Hank<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che le stringhe nella colonna dipendente ora sono separate dal simbolo <strong>&amp;<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : puoi trovare la documentazione completa dell&#8217;operazione GroupBy in panda <a href=\"https:\/\/pandas.pydata.org\/docs\/reference\/api\/pandas.DataFrame.groupby.html\" target=\"_blank\" rel=\"noopener\">qui<\/a> .<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h3>\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\/somma-cumulativa-dei-panda-per-gruppo\/\" target=\"_blank\" rel=\"noopener\">Panda: come calcolare il cumulato per gruppo<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/panda-groupby-conta-unico\/\" target=\"_blank\" rel=\"noopener\">Panda: come contare i valori unici per gruppo<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/gruppo-di-panda-per-correlazione\/\" target=\"_blank\" rel=\"noopener\">Panda: come calcolare la correlazione per gruppo<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare la seguente sintassi di base per concatenare stringhe da GroupBy in panda: df. groupby ([&#8216; group_var &#8216;], as_index= False ). agg ({&#8216; string_var &#8216;: &#8216; &#8216; .join }) Questa particolare formula raggruppa le righe in base alla colonna group_var , quindi concatena le stringhe nella colonna string_var . L&#8217;esempio seguente mostra come [&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 concatenare stringhe utilizzando GroupBy - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come concatenare le stringhe in un DataFrame panda da un GroupBy.\" \/>\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\/i-panda-raggruppano-per-concatenare-stringhe\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Panda: come concatenare stringhe utilizzando GroupBy - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come concatenare le stringhe in un DataFrame panda da un GroupBy.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/i-panda-raggruppano-per-concatenare-stringhe\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-20T02:21: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=\"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\/i-panda-raggruppano-per-concatenare-stringhe\/\",\"url\":\"https:\/\/statorials.org\/it\/i-panda-raggruppano-per-concatenare-stringhe\/\",\"name\":\"Panda: come concatenare stringhe utilizzando GroupBy - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-20T02:21:24+00:00\",\"dateModified\":\"2023-07-20T02:21:24+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come concatenare le stringhe in un DataFrame panda da un GroupBy.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/i-panda-raggruppano-per-concatenare-stringhe\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/i-panda-raggruppano-per-concatenare-stringhe\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/i-panda-raggruppano-per-concatenare-stringhe\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Panda: come concatenare stringhe utilizzando 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 concatenare stringhe utilizzando GroupBy - Statorials","description":"Questo tutorial spiega come concatenare le stringhe in un DataFrame panda da un GroupBy.","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\/i-panda-raggruppano-per-concatenare-stringhe\/","og_locale":"it_IT","og_type":"article","og_title":"Panda: come concatenare stringhe utilizzando GroupBy - Statorials","og_description":"Questo tutorial spiega come concatenare le stringhe in un DataFrame panda da un GroupBy.","og_url":"https:\/\/statorials.org\/it\/i-panda-raggruppano-per-concatenare-stringhe\/","og_site_name":"Statorials","article_published_time":"2023-07-20T02:21:24+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\/i-panda-raggruppano-per-concatenare-stringhe\/","url":"https:\/\/statorials.org\/it\/i-panda-raggruppano-per-concatenare-stringhe\/","name":"Panda: come concatenare stringhe utilizzando GroupBy - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-20T02:21:24+00:00","dateModified":"2023-07-20T02:21:24+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come concatenare le stringhe in un DataFrame panda da un GroupBy.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/i-panda-raggruppano-per-concatenare-stringhe\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/i-panda-raggruppano-per-concatenare-stringhe\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/i-panda-raggruppano-per-concatenare-stringhe\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Panda: come concatenare stringhe utilizzando 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\/2921"}],"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=2921"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2921\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=2921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=2921"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=2921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}