{"id":3196,"date":"2023-07-18T18:13:36","date_gmt":"2023-07-18T18:13:36","guid":{"rendered":"https:\/\/statorials.org\/it\/il-valore-seriale-di-python-verite-e-ambiguo\/"},"modified":"2023-07-18T18:13:36","modified_gmt":"2023-07-18T18:13:36","slug":"il-valore-seriale-di-python-verite-e-ambiguo","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/il-valore-seriale-di-python-verite-e-ambiguo\/","title":{"rendered":"Come risolvere in pandas: il valore di verit\u00e0 di una serie \u00e8 ambiguo"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Un errore che potresti riscontrare in Python \u00e8:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #ff0000;\">ValueError<\/span> : The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(),\n            a.any() or a.all().\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo errore si verifica in genere quando si tenta di filtrare un DataFrame panda utilizzando le parole <strong>e<\/strong> e <strong>o<\/strong> invece di utilizzare i <strong>caratteri &amp;<\/strong> e <strong>|<\/strong> gli operatori.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Questo tutorial spiega come risolvere questo errore nella pratica.<\/span><\/p>\n<h3> <strong>Come riprodurre l&#8217;errore<\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di creare il seguente DataFrame 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;\">#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;\">points<\/span> ': [18, 22, 19, 14, 14, 11, 20, 28],\n                   ' <span style=\"color: #ff0000;\">assists<\/span> ': [5, 7, 7, 9, 12, 9, 9, 4],\n                   ' <span style=\"color: #ff0000;\">rebounds<\/span> ': [11, 8, 10, 6, 6, 5, 9, 12]})\n\n<span style=\"color: #008080;\">#view DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n  team points assists rebounds\n0 A 18 5 11\n1 to 22 7 8\n2 A 19 7 10\n3 A 14 9 6\n4 B 14 12 6\n5 B 11 9 5\n6 B 20 9 9\n7 B 28 4 12\n<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Supponiamo ora di provare a filtrare le righe in cui la squadra \u00e8 uguale ad &#8220;A&#8221; <strong>e<\/strong> i punti sono inferiori a 20:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#attempt to filter DataFrame\n<\/span>df[(df[' <span style=\"color: #ff0000;\">team<\/span> '] == ' <span style=\"color: #ff0000;\">A<\/span> ') <span style=\"color: #008000;\">and<\/span> (df[' <span style=\"color: #ff0000;\">points<\/span> '] &lt; <span style=\"color: #008000;\">20<\/span> )]\n\n<span style=\"color: #ff0000;\">ValueError<\/span> : The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(),\n            a.any() or a.all().\n<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Oppure supponiamo di provare a filtrare le righe dove la squadra \u00e8 uguale ad &#8220;A&#8221; <b>o<\/b> dove i punti sono inferiori a 20:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#attempt to filter DataFrame\n<\/span><span style=\"color: #000000;\">df[(df['<\/span> <span style=\"color: #ff0000;\">team<\/span> <span style=\"color: #000000;\">'] == '<\/span> <span style=\"color: #ff0000;\">A<\/span> <span style=\"color: #000000;\">')<\/span> <span style=\"color: #008000;\">or<\/span> <span style=\"color: #000000;\">(df['<\/span> <span style=\"color: #ff0000;\">points<\/span> <span style=\"color: #000000;\">'] &lt;<\/span> <span style=\"color: #008000;\">20<\/span> <span style=\"color: #000000;\">)]\n\n<\/span><span style=\"color: #ff0000;\">ValueError<\/span> <span style=\"color: #000000;\">: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(),\n            a.any() or a.all().<\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">In entrambi gli scenari riceviamo un errore che ci informa che il valore di verit\u00e0 di una serie \u00e8 ambiguo.<\/span><\/p>\n<h3> <strong>Come correggere l&#8217;errore<\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Per evitare questo errore durante il filtraggio, dobbiamo assicurarci di utilizzare <strong>&amp;<\/strong> e <strong>|<\/strong> elementi. gli operatori.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Ad esempio, possiamo utilizzare il seguente codice per filtrare le righe in cui la squadra \u00e8 uguale ad &#8220;A&#8221; <strong>e<\/strong> i punti sono inferiori a 20:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#filter DataFrame\n<\/span><span style=\"color: #000000;\">df[(df['<\/span> <span style=\"color: #ff0000;\">team<\/span> <span style=\"color: #000000;\">'] == '<\/span> <span style=\"color: #ff0000;\">A<\/span> <span style=\"color: #000000;\">')<\/span> <span style=\"color: #008000;\">&amp;<\/span> <span style=\"color: #000000;\">(df['<\/span> <span style=\"color: #ff0000;\">points<\/span> <span style=\"color: #000000;\">'] &lt;<\/span> <span style=\"color: #008000;\">20<\/span> <span style=\"color: #000000;\">)]\n\n<\/span><span style=\"color: #000000;\">team points assists rebounds\n0 A 18 5 11\n2 A 19 7 10\n3 A 14 9 6<\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Oppure potremmo utilizzare il seguente codice per filtrare le righe in cui la squadra \u00e8 uguale ad &#8220;A&#8221; <b>o<\/b> i punti sono inferiori a 20:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#filter DataFrame\n<\/span>df[(df[' <span style=\"color: #ff0000;\">team<\/span> '] == ' <span style=\"color: #ff0000;\">A<\/span> ') <span style=\"color: #008000;\">|<\/span> (df[' <span style=\"color: #ff0000;\">points<\/span> '] &lt; <span style=\"color: #008000;\">20<\/span> )]\n\n        team points assists rebounds\n0 A 18 5 11\n1 to 22 7 8\n2 A 19 7 10\n3 A 14 9 6\n4 B 14 12 6\n5 B 11 9 5<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">In entrambi gli scenari non riceviamo un errore poich\u00e9 abbiamo utilizzato <strong>&amp;<\/strong> e <strong>|<\/strong> elementi. gli operatori.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : \u00e8 importante includere parentesi attorno a ogni singola condizione quando si filtra un DataFrame panda in base a pi\u00f9 condizioni, altrimenti verr\u00e0 visualizzato un errore.<\/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 correggere altri errori comuni in Python:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\" target=\"_blank\" rel=\"noopener\">Come risolvere il problema: il modulo &#8220;pandas&#8221; non ha l&#8217;attributo &#8220;dataframe&#8221;.<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/impostazione-panda-con-avviso-di-copia\/\" target=\"_blank\" rel=\"noopener\">Come risolvere il problema in Panda: SettingWithCopyWarning<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/panda-typeerror-nessun-dato-numerico-da-tracciare\/\" target=\"_blank\" rel=\"noopener\">Come risolvere il problema in Panda: TypeError: nessun dato numerico da tracciare<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Un errore che potresti riscontrare in Python \u00e8: ValueError : The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). Questo errore si verifica in genere quando si tenta di filtrare un DataFrame panda utilizzando le parole e e o invece di utilizzare i caratteri &amp; e | gli operatori. [&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 risolvere in Panda: il valore di verit\u00e0 di una serie \u00e8 ambiguo - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come correggere il seguente errore in Python: ValueError: il valore di verit\u00e0 di una serie \u00e8 ambiguo. Utilizzare a.empty, a.bool(), a.item(), a.any() o a.all().\" \/>\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\/il-valore-seriale-di-python-verite-e-ambiguo\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come risolvere in Panda: il valore di verit\u00e0 di una serie \u00e8 ambiguo - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come correggere il seguente errore in Python: ValueError: il valore di verit\u00e0 di una serie \u00e8 ambiguo. Utilizzare a.empty, a.bool(), a.item(), a.any() o a.all().\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/il-valore-seriale-di-python-verite-e-ambiguo\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-18T18:13:36+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\/il-valore-seriale-di-python-verite-e-ambiguo\/\",\"url\":\"https:\/\/statorials.org\/it\/il-valore-seriale-di-python-verite-e-ambiguo\/\",\"name\":\"Come risolvere in Panda: il valore di verit\u00e0 di una serie \u00e8 ambiguo - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-18T18:13:36+00:00\",\"dateModified\":\"2023-07-18T18:13:36+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come correggere il seguente errore in Python: ValueError: il valore di verit\u00e0 di una serie \u00e8 ambiguo. Utilizzare a.empty, a.bool(), a.item(), a.any() o a.all().\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/il-valore-seriale-di-python-verite-e-ambiguo\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/il-valore-seriale-di-python-verite-e-ambiguo\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/il-valore-seriale-di-python-verite-e-ambiguo\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come risolvere in pandas: il valore di verit\u00e0 di una serie \u00e8 ambiguo\"}]},{\"@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 risolvere in Panda: il valore di verit\u00e0 di una serie \u00e8 ambiguo - Statorials","description":"Questo tutorial spiega come correggere il seguente errore in Python: ValueError: il valore di verit\u00e0 di una serie \u00e8 ambiguo. Utilizzare a.empty, a.bool(), a.item(), a.any() o a.all().","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\/il-valore-seriale-di-python-verite-e-ambiguo\/","og_locale":"it_IT","og_type":"article","og_title":"Come risolvere in Panda: il valore di verit\u00e0 di una serie \u00e8 ambiguo - Statorials","og_description":"Questo tutorial spiega come correggere il seguente errore in Python: ValueError: il valore di verit\u00e0 di una serie \u00e8 ambiguo. Utilizzare a.empty, a.bool(), a.item(), a.any() o a.all().","og_url":"https:\/\/statorials.org\/it\/il-valore-seriale-di-python-verite-e-ambiguo\/","og_site_name":"Statorials","article_published_time":"2023-07-18T18:13:36+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\/il-valore-seriale-di-python-verite-e-ambiguo\/","url":"https:\/\/statorials.org\/it\/il-valore-seriale-di-python-verite-e-ambiguo\/","name":"Come risolvere in Panda: il valore di verit\u00e0 di una serie \u00e8 ambiguo - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-18T18:13:36+00:00","dateModified":"2023-07-18T18:13:36+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come correggere il seguente errore in Python: ValueError: il valore di verit\u00e0 di una serie \u00e8 ambiguo. Utilizzare a.empty, a.bool(), a.item(), a.any() o a.all().","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/il-valore-seriale-di-python-verite-e-ambiguo\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/il-valore-seriale-di-python-verite-e-ambiguo\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/il-valore-seriale-di-python-verite-e-ambiguo\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come risolvere in pandas: il valore di verit\u00e0 di una serie \u00e8 ambiguo"}]},{"@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\/3196"}],"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=3196"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3196\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}