{"id":3270,"date":"2023-07-18T09:13:21","date_gmt":"2023-07-18T09:13:21","guid":{"rendered":"https:\/\/statorials.org\/it\/i-panda-filtrano-le-linee-in-base-alla-lunghezza-della-stringa\/"},"modified":"2023-07-18T09:13:21","modified_gmt":"2023-07-18T09:13:21","slug":"i-panda-filtrano-le-linee-in-base-alla-lunghezza-della-stringa","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/i-panda-filtrano-le-linee-in-base-alla-lunghezza-della-stringa\/","title":{"rendered":"Panda: come filtrare le righe in base alla lunghezza della stringa"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare i seguenti metodi per filtrare le righe contenenti una stringa di una lunghezza specifica in un DataFrame panda:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: filtrare le righe in base alla lunghezza della stringa in una colonna<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#filter rows where col1 has a string length of 5<\/span>\ndf. <span style=\"color: #3366ff;\">loc<\/span> [df[' <span style=\"color: #ff0000;\">col1<\/span> ']. <span style=\"color: #3366ff;\">str<\/span> . <span style=\"color: #3366ff;\">len<\/span> () == <span style=\"color: #008000;\">5<\/span> ]\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: filtra le righe in base alla lunghezza della stringa di pi\u00f9<\/strong><\/span> <span style=\"color: #000000;\"><strong>colonne<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#filter rows where col1 has string length of 5 and col2 has string length of 7<\/span>\ndf. <span style=\"color: #3366ff;\">loc<\/span> [(df[' <span style=\"color: #ff0000;\">col1<\/span> ']. <span style=\"color: #3366ff;\">str<\/span> . <span style=\"color: #3366ff;\">len<\/span> () == <span style=\"color: #008000;\">5<\/span> ) &amp; (df[' <span style=\"color: #ff0000;\">col2<\/span> ']. <span style=\"color: #3366ff;\">str<\/span> . <span style=\"color: #3366ff;\">len<\/span> () == <span style=\"color: #008000;\">7<\/span> )]\n<\/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;\"> <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;\">conf<\/span> ': ['East', 'East', 'North', 'West', 'North', 'South'],\n                   ' <span style=\"color: #ff0000;\">pos<\/span> ': ['Guard', 'Guard', 'Forward', 'Center', 'Center', 'Forward'],\n                   ' <span style=\"color: #ff0000;\">points<\/span> ': [5, 7, 7, 9, 12, 9]})\n\n<span style=\"color: #008080;\">#view DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n    conf pos points\n0 East Guard 5\n1 East Guard 7\n2 North Forward 7\n3 West Center 9\n4 North Center 12\n5 South Forward 9<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 1: filtra le righe in base alla lunghezza della stringa in una colonna<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come filtrare le righe dal DataFrame che hanno una lunghezza di stringa pari a <strong>5<\/strong> nella colonna <strong>conf<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#filter rows where conf has a string length of 5<\/span>\ndf. <span style=\"color: #3366ff;\">loc<\/span> [df[' <span style=\"color: #ff0000;\">conf<\/span> ']. <span style=\"color: #3366ff;\">str<\/span> . <span style=\"color: #3366ff;\">len<\/span> () == <span style=\"color: #008000;\">5<\/span> ]\n\n\tconf pos points\n2 North Forward 7\n4 North Center 12\n5 South Forward 9\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Vengono restituite solo le righe in cui la colonna <strong>conf<\/strong> ha una lunghezza di stringa pari a <strong>5<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Possiamo vedere che due stringhe diverse soddisfano questo criterio nella colonna <strong>conf<\/strong> :<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">&#8220;Nord&#8221;<\/span><\/li>\n<li> <span style=\"color: #000000;\">&#8220;Sud&#8221;<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Entrambe le stringhe hanno una lunghezza di <strong>5<\/strong> .<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: filtra le righe in base alla lunghezza della stringa di pi\u00f9 colonne<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come filtrare le righe dal DataFrame che hanno una lunghezza di stringa pari a <strong>5<\/strong> nella colonna <strong>conf<\/strong> e una lunghezza di stringa pari <strong>a 7<\/strong> nella colonna <strong>pos<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#filter rows where conf has string length of 5 and pos has string length of 7<\/span>\ndf. <span style=\"color: #3366ff;\">loc<\/span> [(df[' <span style=\"color: #ff0000;\">conf<\/span> ']. <span style=\"color: #3366ff;\">str<\/span> . <span style=\"color: #3366ff;\">len<\/span> () == <span style=\"color: #008000;\">5<\/span> ) &amp; (df[' <span style=\"color: #ff0000;\">pos<\/span> ']. <span style=\"color: #3366ff;\">str<\/span> . <span style=\"color: #3366ff;\">len<\/span> () == <span style=\"color: #008000;\">7<\/span> )]\n\n        conf pos points\n2 North Forward 7\n5 South Forward 9\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Vengono restituite solo le righe in cui la colonna <strong>conf<\/strong> ha una lunghezza di stringa pari a <strong>5<\/strong> e la colonna <strong>pos<\/strong> ha una lunghezza di forza pari a <strong>7<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : puoi trovare la documentazione completa della funzione <strong>str.len()<\/strong> in panda <a href=\"https:\/\/pandas.pydata.org\/docs\/reference\/api\/pandas.Series.str.len.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\/i-panda-rilasciano-file-con-condizione\/\" target=\"_blank\" rel=\"noopener\">Come eliminare le righe in Pandas DataFrame in base alle condizioni<\/a><br \/><a href=\"https:\/\/statorials.org\/it\/i-panda-filtrano-piu-condizioni\/\" target=\"_blank\" rel=\"noopener\">Come filtrare un Pandas DataFrame su pi\u00f9 condizioni<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/panda-assenti\/\" target=\"_blank\" rel=\"noopener\">Come utilizzare il filtro &#8220;NOT IN&#8221; in Pandas DataFrame<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare i seguenti metodi per filtrare le righe contenenti una stringa di una lunghezza specifica in un DataFrame panda: Metodo 1: filtrare le righe in base alla lunghezza della stringa in una colonna #filter rows where col1 has a string length of 5 df. loc [df[&#8216; col1 &#8216;]. str . len () == [&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 filtrare le righe in base alla lunghezza della stringa \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come filtrare le righe in un DataFrame Panda in base alla lunghezza della stringa, 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\/i-panda-filtrano-le-linee-in-base-alla-lunghezza-della-stringa\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Panda: come filtrare le righe in base alla lunghezza della stringa \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come filtrare le righe in un DataFrame Panda in base alla lunghezza della stringa, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/i-panda-filtrano-le-linee-in-base-alla-lunghezza-della-stringa\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-18T09:13:21+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-filtrano-le-linee-in-base-alla-lunghezza-della-stringa\/\",\"url\":\"https:\/\/statorials.org\/it\/i-panda-filtrano-le-linee-in-base-alla-lunghezza-della-stringa\/\",\"name\":\"Panda: come filtrare le righe in base alla lunghezza della stringa \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-18T09:13:21+00:00\",\"dateModified\":\"2023-07-18T09:13:21+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come filtrare le righe in un DataFrame Panda in base alla lunghezza della stringa, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/i-panda-filtrano-le-linee-in-base-alla-lunghezza-della-stringa\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/i-panda-filtrano-le-linee-in-base-alla-lunghezza-della-stringa\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/i-panda-filtrano-le-linee-in-base-alla-lunghezza-della-stringa\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Panda: come filtrare le righe in base alla lunghezza della stringa\"}]},{\"@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 filtrare le righe in base alla lunghezza della stringa \u2013 Statorials","description":"Questo tutorial spiega come filtrare le righe in un DataFrame Panda in base alla lunghezza della stringa, 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\/i-panda-filtrano-le-linee-in-base-alla-lunghezza-della-stringa\/","og_locale":"it_IT","og_type":"article","og_title":"Panda: come filtrare le righe in base alla lunghezza della stringa \u2013 Statorials","og_description":"Questo tutorial spiega come filtrare le righe in un DataFrame Panda in base alla lunghezza della stringa, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/i-panda-filtrano-le-linee-in-base-alla-lunghezza-della-stringa\/","og_site_name":"Statorials","article_published_time":"2023-07-18T09:13:21+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-filtrano-le-linee-in-base-alla-lunghezza-della-stringa\/","url":"https:\/\/statorials.org\/it\/i-panda-filtrano-le-linee-in-base-alla-lunghezza-della-stringa\/","name":"Panda: come filtrare le righe in base alla lunghezza della stringa \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-18T09:13:21+00:00","dateModified":"2023-07-18T09:13:21+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come filtrare le righe in un DataFrame Panda in base alla lunghezza della stringa, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/i-panda-filtrano-le-linee-in-base-alla-lunghezza-della-stringa\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/i-panda-filtrano-le-linee-in-base-alla-lunghezza-della-stringa\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/i-panda-filtrano-le-linee-in-base-alla-lunghezza-della-stringa\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Panda: come filtrare le righe in base alla lunghezza della stringa"}]},{"@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\/3270"}],"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=3270"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3270\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}