{"id":1734,"date":"2023-07-25T05:07:32","date_gmt":"2023-07-25T05:07:32","guid":{"rendered":"https:\/\/statorials.org\/it\/i-panda-rilasciano-una-riga-per-indice\/"},"modified":"2023-07-25T05:07:32","modified_gmt":"2023-07-25T05:07:32","slug":"i-panda-rilasciano-una-riga-per-indice","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/i-panda-rilasciano-una-riga-per-indice\/","title":{"rendered":"Come eliminare righe per indice in panda (con esempi)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare la seguente sintassi per eliminare una riga da un DataFrame panda in base al numero di indice:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#drop first row from DataFrame<\/span>\ndf = df. <span style=\"color: #3366ff;\">drop<\/span> (index= <span style=\"color: #008000;\">0<\/span> )\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Ed \u00e8 possibile utilizzare la seguente sintassi per eliminare pi\u00f9 righe da un DataFrame panda in base ai numeri di indice:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#drop first, second, and fourth row from DataFrame\n<\/span>df = df. <span style=\"color: #3366ff;\">drop<\/span> ( <span style=\"color: #008000;\">index=[0,1,3<\/span> <span style=\"color: #008000;\">]<\/span> <span style=\"color: #008000;\">)<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Se il tuo DataFrame ha stringhe come valori di indice, puoi semplicemente passare i nomi come stringhe per rimuovere:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>df = df. <span style=\"color: #3366ff;\">drop<\/span> (index=[' <span style=\"color: #ff0000;\">first<\/span> ', ' <span style=\"color: #ff0000;\">second<\/span> ', ' <span style=\"color: #ff0000;\">third<\/span> '])\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Gli esempi seguenti mostrano come eliminare in pratica le righe per indice.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 1: elimina una riga per indice<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come eliminare la seconda riga in un DataFrame panda:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">import<\/span> pandas <span style=\"color: #008000;\">as<\/span> pd<\/span>\n\n#createDataFrame\n<span style=\"color: #000000;\">df = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">team<\/span> ': ['Mavs', 'Lakers', 'Spurs', 'Cavs'],\n                   ' <span style=\"color: #ff0000;\">first<\/span> ': ['Dirk', 'Kobe', 'Tim', 'Lebron'],\n                   ' <span style=\"color: #ff0000;\">last<\/span> ': ['Nowitzki', 'Bryant', 'Duncan', 'James'],\n                   ' <span style=\"color: #ff0000;\">points<\/span> ': [26, 31, 22, 29]})\n\n<\/span>#view DataFrame\n<span style=\"color: #000000;\">df\n\n<\/span><span style=\"color: #000000;\">team first last<\/span> <span style=\"color: #000000;\">points\n0 Mavs Dirk Nowitzki<\/span> <span style=\"color: #000000;\">26\n1 Lakers Kobe Bryant<\/span> <span style=\"color: #000000;\">31\n2 Spurs Tim Duncan<\/span> <span style=\"color: #000000;\">22\n3 Cavs LeBron James<\/span> <span style=\"color: #000000;\">29<\/span>\n\n#drop second row from DataFrame<\/span>\ndf = df. <span style=\"color: #3366ff;\">drop<\/span> (index= <span style=\"color: #008000;\">1<\/span> ) \n\n<span style=\"color: #008080;\">#view resulting dataFrame<\/span>\ndf\n\n        team first last points\n0 Mavs Dirk Nowitzki 26\n2 Spurs Tim Duncan 22\n3 Cavs LeBron James 29\n<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: elimina pi\u00f9 righe per indice<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come eliminare pi\u00f9 righe in un DataFrame panda per indice:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">import<\/span> pandas <span style=\"color: #008000;\">as<\/span> pd<\/span>\n\n#createDataFrame\n<span style=\"color: #000000;\">df = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">team<\/span> ': ['Mavs', 'Lakers', 'Spurs', 'Cavs'],\n                   ' <span style=\"color: #ff0000;\">first<\/span> ': ['Dirk', 'Kobe', 'Tim', 'Lebron'],\n                   ' <span style=\"color: #ff0000;\">last<\/span> ': ['Nowitzki', 'Bryant', 'Duncan', 'James'],\n                   ' <span style=\"color: #ff0000;\">points<\/span> ': [26, 31, 22, 29]})\n\n<\/span>#view DataFrame\n<span style=\"color: #000000;\">df\n\n<\/span><span style=\"color: #000000;\">team first last<\/span> <span style=\"color: #000000;\">points\n0 Mavs Dirk Nowitzki<\/span> <span style=\"color: #000000;\">26\n1 Lakers Kobe Bryant<\/span> <span style=\"color: #000000;\">31\n2 Spurs Tim Duncan<\/span> <span style=\"color: #000000;\">22\n3 Cavs LeBron James<\/span> <span style=\"color: #000000;\">29<\/span>\n\n#drop first, second, and fourth row from DataFrame<\/span>\ndf = df. <span style=\"color: #3366ff;\">drop<\/span> ( <span style=\"color: #008000;\">index=[0,1,3<\/span> <span style=\"color: #008000;\">]<\/span> ) \n\n<span style=\"color: #008080;\">#view resulting dataFrame<\/span>\ndf\n\n\tteam first last points\n2 Spurs Tim Duncan 22<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 3: Elimina righe quando l&#8217;indice \u00e8 una stringa<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come rimuovere righe da un DataFrame panda in base all&#8217;indice quando l&#8217;indice \u00e8 una stringa anzich\u00e9 un numero:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">import<\/span> pandas <span style=\"color: #008000;\">as<\/span> pd<\/span>\n\n#createDataFrame\n<span style=\"color: #000000;\">df = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">team<\/span> ': ['Mavs', 'Lakers', 'Spurs', 'Cavs'],\n                   ' <span style=\"color: #ff0000;\">last<\/span> ': ['Nowitzki', 'Bryant', 'Duncan', 'James'],\n                   ' <span style=\"color: #ff0000;\">last<\/span> ': ['Nowitzki', 'Bryant', 'Duncan', 'James'],\n                   ' <span style=\"color: #ff0000;\">points<\/span> ': [26, 31, 22, 29]},\n                   index=['A', 'B', 'C', 'D'])\n\n<\/span>#view DataFrame\n<span style=\"color: #000000;\">df\n<\/span><span style=\"color: #000000;\">team first last<\/span> <span style=\"color: #000000;\">points\nA Mavs Dirk Nowitzki<\/span> <span style=\"color: #000000;\">26\nB Lakers Kobe Bryant<\/span> <span style=\"color: #000000;\">31\nC Spurs Tim Duncan<\/span> <span style=\"color: #000000;\">22\nD Cavs Lebron James<\/span> <span style=\"color: #000000;\">29\n<\/span>\n#remove rows with index values 'A' and 'C'\n<span style=\"color: #000000;\">df = df. <span style=\"color: #3366ff;\">drop<\/span> (index=[' <span style=\"color: #ff0000;\">A<\/span> ',' <span style=\"color: #ff0000;\">C<\/span> '])\n<\/span>\n#view resulting DataFrame\n<span style=\"color: #000000;\">df\n\nteam first last points\nB Lakers Kobe Bryant 31\nD Cavs Lebron James 29<\/span><\/span><\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/it\/i-panda-rilasciano-colonna-per-indice\/\" target=\"_blank\" rel=\"noopener\">Come eliminare le colonne per indice in Pandas<\/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<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare la seguente sintassi per eliminare una riga da un DataFrame panda in base al numero di indice: #drop first row from DataFrame df = df. drop (index= 0 ) Ed \u00e8 possibile utilizzare la seguente sintassi per eliminare pi\u00f9 righe da un DataFrame panda in base ai numeri di indice: #drop first, [&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 eliminare righe per indice in Panda (con esempi)<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come eliminare righe per indice in un DataFrame panda, 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-rilasciano-una-riga-per-indice\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come eliminare righe per indice in Panda (con esempi)\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come eliminare righe per indice in un DataFrame panda, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/i-panda-rilasciano-una-riga-per-indice\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-25T05:07:32+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-rilasciano-una-riga-per-indice\/\",\"url\":\"https:\/\/statorials.org\/it\/i-panda-rilasciano-una-riga-per-indice\/\",\"name\":\"Come eliminare righe per indice in Panda (con esempi)\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-25T05:07:32+00:00\",\"dateModified\":\"2023-07-25T05:07:32+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come eliminare righe per indice in un DataFrame panda, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/i-panda-rilasciano-una-riga-per-indice\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/i-panda-rilasciano-una-riga-per-indice\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/i-panda-rilasciano-una-riga-per-indice\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come eliminare righe per indice in panda (con esempi)\"}]},{\"@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 eliminare righe per indice in Panda (con esempi)","description":"Questo tutorial spiega come eliminare righe per indice in un DataFrame panda, 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-rilasciano-una-riga-per-indice\/","og_locale":"it_IT","og_type":"article","og_title":"Come eliminare righe per indice in Panda (con esempi)","og_description":"Questo tutorial spiega come eliminare righe per indice in un DataFrame panda, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/i-panda-rilasciano-una-riga-per-indice\/","og_site_name":"Statorials","article_published_time":"2023-07-25T05:07:32+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-rilasciano-una-riga-per-indice\/","url":"https:\/\/statorials.org\/it\/i-panda-rilasciano-una-riga-per-indice\/","name":"Come eliminare righe per indice in Panda (con esempi)","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-25T05:07:32+00:00","dateModified":"2023-07-25T05:07:32+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come eliminare righe per indice in un DataFrame panda, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/i-panda-rilasciano-una-riga-per-indice\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/i-panda-rilasciano-una-riga-per-indice\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/i-panda-rilasciano-una-riga-per-indice\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come eliminare righe per indice in panda (con esempi)"}]},{"@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\/1734"}],"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=1734"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/1734\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=1734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=1734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=1734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}