{"id":1651,"date":"2023-07-25T12:40:45","date_gmt":"2023-07-25T12:40:45","guid":{"rendered":"https:\/\/statorials.org\/it\/conte-di-pitone\/"},"modified":"2023-07-25T12:40:45","modified_gmt":"2023-07-25T12:40:45","slug":"conte-di-pitone","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/conte-di-pitone\/","title":{"rendered":"Come eseguire una funzione conta.se in python"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Spesso potresti voler contare solo il numero di righe in un DataFrame panda che soddisfa determinati criteri.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Fortunatamente, questo \u00e8 facile da fare utilizzando la seguente sintassi di base:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>sum(df. <span style=\"color: #3366ff;\">column_name<\/span> == <span style=\"color: #008000;\">some_value<\/span> )\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">I seguenti esempi mostrano come utilizzare in pratica questa sintassi sul seguente frame di dati:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><b><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;\">x<\/span> ': [3, 4, 5, 6, 7, 8, 9, 10, 10, 12, 13],\n                   ' <span style=\"color: #ff0000;\">y<\/span> ': [3, 4, 5, 7, 9, 13, 15, 19, 23, 24, 29]})\n\n<span style=\"color: #008080;\">#view head of DataFrame\n<\/span>df. <span style=\"color: #3366ff;\">head<\/span> ()\n\nx y\n0 3 3\n1 4 4\n2 5 5\n3 6 7\n4 7 9\n<\/b><\/span><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 1: contare le righe pari a un determinato valore<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come contare il numero di righe in cui la variabile x \u00e8 uguale a 10:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>sum( <span style=\"color: #3366ff;\">df.x<\/span> == <span style=\"color: #008000;\">10<\/span> )\n\n2\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come contare il numero di righe in cui la variabile x \u00e8 uguale a 10 <em>o<\/em> la variabile y \u00e8 uguale a 5:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>sum((df. <span style=\"color: #3366ff;\">x<\/span> == <span style=\"color: #008000;\">10<\/span> ) | (df. <span style=\"color: #3366ff;\">y<\/span> == <span style=\"color: #008000;\">5<\/span> ))\n\n3<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come contare il numero di righe in cui la variabile x <em>non \u00e8<\/em> uguale a 10:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>sum( <span style=\"color: #3366ff;\">df.x<\/span> != <span style=\"color: #008000;\">10<\/span> )\n\n9<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: conteggio delle righe maggiori o uguali a un determinato valore<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come contare il numero di righe in cui x \u00e8 maggiore di 10:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>sum( <span style=\"color: #3366ff;\">df.x<\/span> &gt; <span style=\"color: #008000;\">10<\/span> ) \n\n2<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come contare il numero di righe in cui x \u00e8 inferiore o uguale a 7:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>sum(df. <span style=\"color: #3366ff;\">x<\/span> &lt;= <span style=\"color: #008000;\">7<\/span> )\n \n5<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 3: contare le linee tra due valori<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come contare il numero di righe in cui x \u00e8 compreso tra 10 e 20:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>sum((df. <span style=\"color: #3366ff;\">x<\/span> &gt;= <span style=\"color: #008000;\">5<\/span> ) &amp; (df. <span style=\"color: #3366ff;\">x<\/span> &lt;= <span style=\"color: #008000;\">10<\/span> ))\n\n7<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/it\/differenza-dei-panda-tra-le-righe\/\" target=\"_blank\" rel=\"noopener\">Panda: come trovare la differenza tra due linee<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/i-panda-rilasciano-righe-che-contengono-stringhe\/\" target=\"_blank\" rel=\"noopener\">Panda: come eliminare le righe contenenti una stringa specifica<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/i-panda-rilasciano-duplicati\/\" target=\"_blank\" rel=\"noopener\">Panda: come rimuovere le righe duplicate in un DataFrame<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spesso potresti voler contare solo il numero di righe in un DataFrame panda che soddisfa determinati criteri. Fortunatamente, questo \u00e8 facile da fare utilizzando la seguente sintassi di base: sum(df. column_name == some_value ) I seguenti esempi mostrano come utilizzare in pratica questa sintassi sul seguente frame di dati: import pandas as pd #createDataFrame df [&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 una funzione CONTA.SE in Python - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come eseguire una funzione COUNTIF in Python, con diversi 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\/conte-di-pitone\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come eseguire una funzione CONTA.SE in Python - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come eseguire una funzione COUNTIF in Python, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/conte-di-pitone\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-25T12:40:45+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\/conte-di-pitone\/\",\"url\":\"https:\/\/statorials.org\/it\/conte-di-pitone\/\",\"name\":\"Come eseguire una funzione CONTA.SE in Python - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-25T12:40:45+00:00\",\"dateModified\":\"2023-07-25T12:40:45+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come eseguire una funzione COUNTIF in Python, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/conte-di-pitone\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/conte-di-pitone\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/conte-di-pitone\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come eseguire una funzione conta.se in python\"}]},{\"@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 una funzione CONTA.SE in Python - Statorials","description":"Questo tutorial spiega come eseguire una funzione COUNTIF in Python, con diversi 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\/conte-di-pitone\/","og_locale":"it_IT","og_type":"article","og_title":"Come eseguire una funzione CONTA.SE in Python - Statorials","og_description":"Questo tutorial spiega come eseguire una funzione COUNTIF in Python, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/conte-di-pitone\/","og_site_name":"Statorials","article_published_time":"2023-07-25T12:40:45+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\/conte-di-pitone\/","url":"https:\/\/statorials.org\/it\/conte-di-pitone\/","name":"Come eseguire una funzione CONTA.SE in Python - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-25T12:40:45+00:00","dateModified":"2023-07-25T12:40:45+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come eseguire una funzione COUNTIF in Python, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/conte-di-pitone\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/conte-di-pitone\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/conte-di-pitone\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come eseguire una funzione conta.se in python"}]},{"@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\/1651"}],"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=1651"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/1651\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=1651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=1651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=1651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}