{"id":3727,"date":"2023-07-15T22:05:44","date_gmt":"2023-07-15T22:05:44","guid":{"rendered":"https:\/\/statorials.org\/it\/panda-controlla-se-la-stringa-contiene-piu-sottostringhe\/"},"modified":"2023-07-15T22:05:44","modified_gmt":"2023-07-15T22:05:44","slug":"panda-controlla-se-la-stringa-contiene-piu-sottostringhe","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/panda-controlla-se-la-stringa-contiene-piu-sottostringhe\/","title":{"rendered":"Panda: controlla se la stringa contiene pi\u00f9 sottostringhe"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare i seguenti metodi per verificare se una stringa in un DataFrame panda contiene pi\u00f9 sottostringhe:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: controlla se la stringa contiene una delle numerose sottostringhe<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>df[' <span style=\"color: #ff0000;\">string_column<\/span> ']. <span style=\"color: #3366ff;\">str<\/span> . <span style=\"color: #3366ff;\">contains<\/span> (' <span style=\"color: #ff0000;\">|<\/span> ' <span style=\"color: #3366ff;\">.join<\/span> ([' <span style=\"color: #ff0000;\">string1<\/span> ',' <span style=\"color: #ff0000;\">string2<\/span> ']))\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: controlla se la stringa contiene pi\u00f9 sottostringhe<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>df[' <span style=\"color: #ff0000;\">string_column<\/span> ']. <span style=\"color: #3366ff;\">str<\/span> . <span style=\"color: #3366ff;\">contains<\/span> ( <span style=\"color: #ff0000;\">r'^(?=.*string1)(?=.*string2)'<\/span> )<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">I seguenti esempi mostrano come utilizzare ciascun metodo nella pratica con i seguenti DataFrame panda:<\/span><\/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> ': ['Good East Team', 'Good West Team', 'Great East Team',\n                             'Great West Team', 'Bad East Team', 'Bad West Team'],\n                   ' <span style=\"color: #ff0000;\">points<\/span> ': [93, 99, 105, 110, 85, 88]})\n\n<span style=\"color: #008080;\">#view DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n              team points\n0 Good East Team 93\n1 Good West Team 99\n2 Great East Team 105\n3 Great West Team 110\n4 Bad East Team 85\n5 Bad West Team 88\n<\/strong><\/span><\/pre>\n<h2> <strong>Esempio<\/strong> <strong>1: <span style=\"color: #000000;\">controlla se la stringa contiene una delle diverse sottostringhe<\/span><\/strong><\/h2>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare la seguente sintassi per verificare se ogni stringa nella colonna <strong>del team<\/strong> contiene la sottostringa &#8220;Buono&#8221; <strong>o<\/strong> &#8220;\u00c8&#8221;:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#create new column that checks if each team name contains 'Good' or 'East'\n<\/span>df[' <span style=\"color: #ff0000;\">good_or_east<\/span> '] = df[' <span style=\"color: #ff0000;\">team<\/span> ']. <span style=\"color: #3366ff;\">str<\/span> . <span style=\"color: #3366ff;\">contains<\/span> (' <span style=\"color: #ff0000;\">|<\/span> ' <span style=\"color: #3366ff;\">.join<\/span> ([' <span style=\"color: #ff0000;\">Good<\/span> ',' <span style=\"color: #ff0000;\">East<\/span> ']))\n\n<span style=\"color: #008080;\">#view updated DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n              team points good_or_east\n0 Good East Team 93 True\n1 Good West Team 99 True\n2 Great East Team 105 True\n3 Great West Team 110 False\n4 Bad East Team 85 True\n5 Bad West Team 88 False<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">La nuova colonna <strong>good_or_east<\/strong> restituisce i seguenti valori:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>Vero<\/strong> se la squadra contiene &#8220;Buono&#8221; o &#8220;\u00c8&#8221;<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>Falso<\/strong> se la squadra non contiene n\u00e9 \u201cBuono\u201d n\u00e9 \u201c\u00c8\u201d<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : il <strong>|<\/strong> L&#8217;operatore significa &#8220;o&#8221; in panda.<\/span><\/p>\n<h2> <strong>Esempio 2<\/strong> <strong>: <span style=\"color: #000000;\">controlla se la stringa contiene pi\u00f9 sottostringhe<\/span><\/strong><\/h2>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare la seguente sintassi per verificare se ogni stringa nella colonna <strong>team<\/strong> contiene la sottostringa \u201cBuono\u201d <b>e<\/b> \u201cIs\u201d:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#create new column that checks if each team name contains 'Good' and 'East'<\/span>\ndf[' <span style=\"color: #ff0000;\">good_and_east<\/span> '] = df[' <span style=\"color: #ff0000;\">team<\/span> ']. <span style=\"color: #3366ff;\">str<\/span> . <span style=\"color: #3366ff;\">contains<\/span> ( <span style=\"color: #ff0000;\">r'^(?=.*Good)(?=.*East)'<\/span> )\n\n<span style=\"color: #008080;\">#view updated DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n              team points good_and_east\n0 Good East Team 93 True\n1 Good West Team 99 False\n2 Great East Team 105 False\n3 Great West Team 110 False\n4 Bad East Team 85 False\n5 Bad West Team 88 False<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">La nuova colonna <strong>good_and_east<\/strong> restituisce i seguenti valori:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>Vero<\/strong> se la squadra contiene &#8220;Buono&#8221; e &#8220;\u00c8&#8221;<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>Falso<\/strong> se la squadra non contiene \u201cBuono\u201d e \u201c\u00c8\u201d<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Tieni presente che viene restituito un solo valore <strong>True<\/strong> poich\u00e9 esiste un solo nome di squadra contenente la sottostringa &#8220;Buono&#8221; <strong>e<\/strong> la sottostringa &#8220;Est&#8221;.<\/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\/panda-aggiunge-una-colonna-da-un-dataframe-a-un-altro\/\" target=\"_blank\" rel=\"noopener\">Panda: aggiungi una colonna da un DataFrame a un altro<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/i-panda-ottengono-righe-non-in-altri-dataframe\/\" target=\"_blank\" rel=\"noopener\">Panda: ottieni righe che non si trovano in un altro DataFrame<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/panda-controlla-se-piu-colonne-sono-uguali\/\" target=\"_blank\" rel=\"noopener\">Panda: come verificare se pi\u00f9 colonne sono uguali<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare i seguenti metodi per verificare se una stringa in un DataFrame panda contiene pi\u00f9 sottostringhe: Metodo 1: controlla se la stringa contiene una delle numerose sottostringhe df[&#8216; string_column &#8216;]. str . contains (&#8216; | &#8216; .join ([&#8216; string1 &#8216;,&#8217; string2 &#8216;])) Metodo 2: controlla se la stringa contiene pi\u00f9 sottostringhe df[&#8216; string_column [&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: controlla se la stringa contiene pi\u00f9 sottostringhe \u2013 Stologia<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come verificare se le stringhe in un DataFrame panda contengono pi\u00f9 sottostringhe, inclusi 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\/panda-controlla-se-la-stringa-contiene-piu-sottostringhe\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Panda: controlla se la stringa contiene pi\u00f9 sottostringhe \u2013 Stologia\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come verificare se le stringhe in un DataFrame panda contengono pi\u00f9 sottostringhe, inclusi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/panda-controlla-se-la-stringa-contiene-piu-sottostringhe\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-15T22:05:44+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\/panda-controlla-se-la-stringa-contiene-piu-sottostringhe\/\",\"url\":\"https:\/\/statorials.org\/it\/panda-controlla-se-la-stringa-contiene-piu-sottostringhe\/\",\"name\":\"Panda: controlla se la stringa contiene pi\u00f9 sottostringhe \u2013 Stologia\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-15T22:05:44+00:00\",\"dateModified\":\"2023-07-15T22:05:44+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come verificare se le stringhe in un DataFrame panda contengono pi\u00f9 sottostringhe, inclusi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/panda-controlla-se-la-stringa-contiene-piu-sottostringhe\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/panda-controlla-se-la-stringa-contiene-piu-sottostringhe\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/panda-controlla-se-la-stringa-contiene-piu-sottostringhe\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Panda: controlla se la stringa contiene pi\u00f9 sottostringhe\"}]},{\"@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: controlla se la stringa contiene pi\u00f9 sottostringhe \u2013 Stologia","description":"Questo tutorial spiega come verificare se le stringhe in un DataFrame panda contengono pi\u00f9 sottostringhe, inclusi 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\/panda-controlla-se-la-stringa-contiene-piu-sottostringhe\/","og_locale":"it_IT","og_type":"article","og_title":"Panda: controlla se la stringa contiene pi\u00f9 sottostringhe \u2013 Stologia","og_description":"Questo tutorial spiega come verificare se le stringhe in un DataFrame panda contengono pi\u00f9 sottostringhe, inclusi esempi.","og_url":"https:\/\/statorials.org\/it\/panda-controlla-se-la-stringa-contiene-piu-sottostringhe\/","og_site_name":"Statorials","article_published_time":"2023-07-15T22:05:44+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\/panda-controlla-se-la-stringa-contiene-piu-sottostringhe\/","url":"https:\/\/statorials.org\/it\/panda-controlla-se-la-stringa-contiene-piu-sottostringhe\/","name":"Panda: controlla se la stringa contiene pi\u00f9 sottostringhe \u2013 Stologia","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-15T22:05:44+00:00","dateModified":"2023-07-15T22:05:44+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come verificare se le stringhe in un DataFrame panda contengono pi\u00f9 sottostringhe, inclusi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/panda-controlla-se-la-stringa-contiene-piu-sottostringhe\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/panda-controlla-se-la-stringa-contiene-piu-sottostringhe\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/panda-controlla-se-la-stringa-contiene-piu-sottostringhe\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Panda: controlla se la stringa contiene pi\u00f9 sottostringhe"}]},{"@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\/3727"}],"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=3727"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3727\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}