{"id":3437,"date":"2023-07-17T12:10:17","date_gmt":"2023-07-17T12:10:17","guid":{"rendered":"https:\/\/statorials.org\/it\/panda-anti-adesione\/"},"modified":"2023-07-17T12:10:17","modified_gmt":"2023-07-17T12:10:17","slug":"panda-anti-adesione","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/panda-anti-adesione\/","title":{"rendered":"Come eseguire un anti-join in pandas"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Un <strong>anti-join<\/strong> consente di restituire tutte le righe in un set di dati che non hanno valori corrispondenti in un altro set di dati.<\/span><\/p>\n<p> <span style=\"color: #000000;\">\u00c8 possibile utilizzare la seguente sintassi per eseguire un anti-join tra due DataFrames panda:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>outer = df1. <span style=\"color: #3366ff;\">merge<\/span> (df2, how=' <span style=\"color: #ff0000;\">outer<\/span> ', indicator= <span style=\"color: #008000;\">True<\/span> )\n\nanti_join = outer[(outer._merge==' <span style=\"color: #ff0000;\">left_only<\/span> ')]. <span style=\"color: #3366ff;\">drop<\/span> (' <span style=\"color: #ff0000;\">_merge<\/span> ', axis= <span style=\"color: #008000;\">1<\/span> )\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">L&#8217;esempio seguente mostra come utilizzare questa sintassi nella pratica.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio: eseguire un anti-join in Pandas<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Supponiamo di avere i seguenti due DataFrames panda:<\/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;\">#create first DataFrame\n<\/span>df1 = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">team<\/span> ': ['A', 'B', 'C', 'D', 'E'],\n                    ' <span style=\"color: #ff0000;\">points<\/span> ': [18, 22, 19, 14, 30]})\n\n<span style=\"color: #008000;\">print<\/span> (df1)\n\n  team points\n0 to 18\n1 B 22\n2 C 19\n3 D 14\n4 E 30\n\n<span style=\"color: #008080;\">#create second DataFrame\n<\/span>df2 = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">team<\/span> ': ['A', 'B', 'C', 'F', 'G'],\n                    ' <span style=\"color: #ff0000;\">points<\/span> ': [18, 22, 19, 22, 29]})\n\n<span style=\"color: #008000;\">print<\/span> (df2)\n\n  team points\n0 to 18\n1 B 22\n2 C 19\n3 F 22\n4 G 29\n<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare il seguente codice per restituire tutte le righe del primo DataFrame che non hanno un team corrispondente nel secondo DataFrame:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#perform outer join<\/span>\nouter = df1. <span style=\"color: #3366ff;\">merge<\/span> (df2, how=' <span style=\"color: #ff0000;\">outer<\/span> ', indicator= <span style=\"color: #008000;\">True<\/span> )\n\n<span style=\"color: #008080;\">#perform anti-join\n<\/span>anti_join = outer[(outer._merge==' <span style=\"color: #ff0000;\">left_only<\/span> ')]. <span style=\"color: #3366ff;\">drop<\/span> (' <span style=\"color: #ff0000;\">_merge<\/span> ', axis= <span style=\"color: #008000;\">1<\/span> )\n\n<span style=\"color: #008080;\">#view results\n<\/span><span style=\"color: #008000;\">print<\/span> (anti_join)\n\n  team points\n3 D 14\n4 E 30<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo vedere che ci sono esattamente due squadre del primo DataFrame che non hanno un nome di squadra corrispondente nel secondo DataFrame.<\/span><\/p>\n<p> <span style=\"color: #000000;\">L&#8217;anti-join ha funzionato come previsto.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Il risultato finale \u00e8 un DataFrame che contiene solo le righe in cui il nome del team appartiene al primo DataFrame ma non al secondo DataFrame.<\/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 attivit\u00e0 comuni nei panda:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/guarnizioni-interne-panda\/\" target=\"_blank\" rel=\"noopener\">Come eseguire un inner join in Pandas<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/a-sinistra-unisciti-ai-panda\/\" target=\"_blank\" rel=\"noopener\">Come eseguire un join a sinistra in Pandas<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/panda-incrociati\/\" target=\"_blank\" rel=\"noopener\">Come eseguire un cross join in Pandas<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Un anti-join consente di restituire tutte le righe in un set di dati che non hanno valori corrispondenti in un altro set di dati. \u00c8 possibile utilizzare la seguente sintassi per eseguire un anti-join tra due DataFrames panda: outer = df1. merge (df2, how=&#8217; outer &#8216;, indicator= True ) anti_join = outer[(outer._merge==&#8217; left_only &#8216;)]. drop [&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>Come eseguire un anti-join in Pandas \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come eseguire un anti-join in Pandas, con un esempio.\" \/>\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-anti-adesione\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come eseguire un anti-join in Pandas \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come eseguire un anti-join in Pandas, con un esempio.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/panda-anti-adesione\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-17T12:10:17+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=\"1 minuto\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/panda-anti-adesione\/\",\"url\":\"https:\/\/statorials.org\/it\/panda-anti-adesione\/\",\"name\":\"Come eseguire un anti-join in Pandas \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-17T12:10:17+00:00\",\"dateModified\":\"2023-07-17T12:10:17+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come eseguire un anti-join in Pandas, con un esempio.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/panda-anti-adesione\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/panda-anti-adesione\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/panda-anti-adesione\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come eseguire un anti-join in pandas\"}]},{\"@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":"Come eseguire un anti-join in Pandas \u2013 Statorials","description":"Questo tutorial spiega come eseguire un anti-join in Pandas, con un esempio.","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-anti-adesione\/","og_locale":"it_IT","og_type":"article","og_title":"Come eseguire un anti-join in Pandas \u2013 Statorials","og_description":"Questo tutorial spiega come eseguire un anti-join in Pandas, con un esempio.","og_url":"https:\/\/statorials.org\/it\/panda-anti-adesione\/","og_site_name":"Statorials","article_published_time":"2023-07-17T12:10:17+00:00","author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"1 minuto"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/panda-anti-adesione\/","url":"https:\/\/statorials.org\/it\/panda-anti-adesione\/","name":"Come eseguire un anti-join in Pandas \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-17T12:10:17+00:00","dateModified":"2023-07-17T12:10:17+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come eseguire un anti-join in Pandas, con un esempio.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/panda-anti-adesione\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/panda-anti-adesione\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/panda-anti-adesione\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come eseguire un anti-join in pandas"}]},{"@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\/3437"}],"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=3437"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3437\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}