{"id":4086,"date":"2023-07-13T17:16:47","date_gmt":"2023-07-13T17:16:47","guid":{"rendered":"https:\/\/statorials.org\/it\/i-panda-leggono-csv-solo-righe-specifiche\/"},"modified":"2023-07-13T17:16:47","modified_gmt":"2023-07-13T17:16:47","slug":"i-panda-leggono-csv-solo-righe-specifiche","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/i-panda-leggono-csv-solo-righe-specifiche\/","title":{"rendered":"Panda: come leggere solo righe specifiche da un file csv"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare la seguente sintassi di base per leggere solo righe specifiche da un file CSV in un DataFrame panda:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\"><span style=\"color: #008080;\">#specify rows to import\n<\/span><span style=\"color: #000000;\">specific_rows = [ <span style=\"color: #008000;\">0<\/span> , <span style=\"color: #008000;\">2<\/span> , <span style=\"color: #008000;\">3<\/span> ]\n<\/span>\n<span style=\"color: #008080;\">#import specific rows from CSV into DataFrame\n<\/span><span style=\"color: #000000;\">df = pd. <span style=\"color: #3366ff;\">read_csv<\/span> (' <span style=\"color: #ff0000;\">my_data.csv<\/span> ', skiprows = <span style=\"color: #008000;\">lambda<\/span> x:x <span style=\"color: #008000;\">not in<\/span> specific_rows)\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo particolare esempio legger\u00e0 le righe nelle posizioni di indice 0, 2 e 3 da un file CSV chiamato <strong>my_data.csv<\/strong> in un DataFrame panda.<\/span><\/p>\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: leggi solo righe specifiche da un file CSV in Pandas<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Supponiamo di avere il seguente file CSV chiamato <strong>basket_data.csv<\/strong> :<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-28596 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/sauter1-1.jpg\" alt=\"\" width=\"435\" height=\"318\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Se utilizziamo la funzione <strong>read_csv()<\/strong> , panda importer\u00e0 automaticamente ogni riga del file CSV in un DataFrame:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <b><span style=\"color: #008000;\">import<\/span> pandas <span style=\"color: #008000;\">as<\/span> pd\n\n<span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#import all rows of CSV into DataFrame\n<span style=\"color: #000000;\">df = pd. <span style=\"color: #3366ff;\">read_csv<\/span> (' <span style=\"color: #ff0000;\">basketball_data.csv<\/span> ')\n\n<span style=\"color: #008080;\">#view DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n  team points rebounds\n0 to 22 10\n1 B 14 9\n2 C 29 6\n3 D 30 2<\/span><\/span><\/strong><\/span><\/b><\/pre>\n<p> <span style=\"color: #000000;\">Tuttavia, possiamo utilizzare la seguente sintassi per importare solo le righe nelle posizioni dell&#8217;indice 0, 2 e 3 dal file CSV in un DataFrame panda:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <b><span style=\"color: #008000;\">import<\/span> pandas <span style=\"color: #008000;\">as<\/span> pd\n\n<span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#specify rows to import\n<span style=\"color: #000000;\">specific_rows = [ <span style=\"color: #008000;\">0<\/span> , <span style=\"color: #008000;\">2<\/span> , <span style=\"color: #008000;\">3<\/span> ]\n\n<span style=\"color: #008080;\">#import specific rows from CSV into DataFrame\n<\/span>df = pd. <span style=\"color: #3366ff;\">read_csv<\/span> (' <span style=\"color: #ff0000;\">basketball_data.csv<\/span> ', skiprows = <span style=\"color: #008000;\">lambda<\/span> x:x <span style=\"color: #008000;\">not in<\/span> specific_rows)\n\n<span style=\"color: #008080;\">#view DataFrame<\/span>\n<span style=\"color: #008000;\">print<\/span> (df)\n\n  team points rebounds\n0 B 14 9\n1 C 29 6\n<\/span><\/span><\/strong><\/span><\/b><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che solo le righe nelle posizioni di indice 0, 2 e 3 del file CSV vengono importate nel DataFrame.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Questa sintassi utilizza l&#8217;argomento <strong>skiprows<\/strong> e una funzione <strong>lambda<\/strong> per indicare ai panda quali righe <em>non devono essere saltate<\/em> durante l&#8217;importazione del file CSV.<\/span><\/p>\n<p> <span style=\"color: #000000;\">In questo esempio, stiamo dicendo ai panda di non ignorare le righe nelle posizioni di indice 0, 2 e 3, ma di ignorare tutte le altre righe durante l&#8217;importazione del file CSV.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : puoi trovare la documentazione completa della funzione panda <strong>read_csv()<\/strong> <a href=\"https:\/\/pandas.pydata.org\/docs\/reference\/api\/pandas.read_csv.html\" target=\"_blank\" rel=\"noopener\">qui<\/a> .<\/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 in Python:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/i-panda-saltano-di-classifica\/\" target=\"_blank\" rel=\"noopener\">Panda: come saltare le righe durante la lettura di un file CSV<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/i-panda-hanno-aggiunto-csv\/\" target=\"_blank\" rel=\"noopener\">Panda: come aggiungere dati a un file CSV esistente<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/i-panda-leggono-il-dtype-csv\/\" target=\"_blank\" rel=\"noopener\">Panda: come specificare i tipi durante l&#8217;importazione di un file CSV<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/i-panda-leggono-la-colonna-del-nome-csv\/\" target=\"_blank\" rel=\"noopener\">Panda: come impostare i nomi delle colonne durante l&#8217;importazione di un file CSV<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare la seguente sintassi di base per leggere solo righe specifiche da un file CSV in un DataFrame panda: #specify rows to import specific_rows = [ 0 , 2 , 3 ] #import specific rows from CSV into DataFrame df = pd. read_csv (&#8216; my_data.csv &#8216;, skiprows = lambda x:x not in specific_rows) [&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 leggere solo righe specifiche da un file CSV - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come leggere solo righe specifiche da un file CSV in un DataFrame panda, 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\/i-panda-leggono-csv-solo-righe-specifiche\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Panda: come leggere solo righe specifiche da un file CSV - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come leggere solo righe specifiche da un file CSV in un DataFrame panda, con un esempio.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/i-panda-leggono-csv-solo-righe-specifiche\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-13T17:16:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/sauter1-1.jpg\" \/>\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-leggono-csv-solo-righe-specifiche\/\",\"url\":\"https:\/\/statorials.org\/it\/i-panda-leggono-csv-solo-righe-specifiche\/\",\"name\":\"Panda: come leggere solo righe specifiche da un file CSV - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-13T17:16:47+00:00\",\"dateModified\":\"2023-07-13T17:16:47+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come leggere solo righe specifiche da un file CSV in un DataFrame panda, con un esempio.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/i-panda-leggono-csv-solo-righe-specifiche\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/i-panda-leggono-csv-solo-righe-specifiche\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/i-panda-leggono-csv-solo-righe-specifiche\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Panda: come leggere solo righe specifiche da un file csv\"}]},{\"@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 leggere solo righe specifiche da un file CSV - Statorials","description":"Questo tutorial spiega come leggere solo righe specifiche da un file CSV in un DataFrame panda, 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\/i-panda-leggono-csv-solo-righe-specifiche\/","og_locale":"it_IT","og_type":"article","og_title":"Panda: come leggere solo righe specifiche da un file CSV - Statorials","og_description":"Questo tutorial spiega come leggere solo righe specifiche da un file CSV in un DataFrame panda, con un esempio.","og_url":"https:\/\/statorials.org\/it\/i-panda-leggono-csv-solo-righe-specifiche\/","og_site_name":"Statorials","article_published_time":"2023-07-13T17:16:47+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/sauter1-1.jpg"}],"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-leggono-csv-solo-righe-specifiche\/","url":"https:\/\/statorials.org\/it\/i-panda-leggono-csv-solo-righe-specifiche\/","name":"Panda: come leggere solo righe specifiche da un file CSV - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-13T17:16:47+00:00","dateModified":"2023-07-13T17:16:47+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come leggere solo righe specifiche da un file CSV in un DataFrame panda, con un esempio.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/i-panda-leggono-csv-solo-righe-specifiche\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/i-panda-leggono-csv-solo-righe-specifiche\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/i-panda-leggono-csv-solo-righe-specifiche\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Panda: come leggere solo righe specifiche da un file csv"}]},{"@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\/4086"}],"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=4086"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/4086\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=4086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=4086"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=4086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}