{"id":1733,"date":"2023-07-25T05:11:30","date_gmt":"2023-07-25T05:11:30","guid":{"rendered":"https:\/\/statorials.org\/it\/i-panda-rilasciano-colonna-per-indice\/"},"modified":"2023-07-25T05:11:30","modified_gmt":"2023-07-25T05:11:30","slug":"i-panda-rilasciano-colonna-per-indice","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/i-panda-rilasciano-colonna-per-indice\/","title":{"rendered":"Come eliminare le colonne per indice in pandas"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare la seguente sintassi per rimuovere una colonna 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 column from DataFrame<\/span>\ndf. <span style=\"color: #3366ff;\">drop<\/span> ( <span style=\"color: #3366ff;\">df.columns<\/span> [0], axis= <span style=\"color: #008000;\">1<\/span> , inplace= <span style=\"color: #008000;\">True<\/span> )\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">E puoi utilizzare la seguente sintassi per rimuovere pi\u00f9 colonne 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 column from DataFrame\n<\/span>cols = [0, 1, 3]\ndf. <span style=\"color: #3366ff;\">drop<\/span> (df. <span style=\"color: #3366ff;\">columns<\/span> [cols], axis= <span style=\"color: #008000;\">1<\/span> , inplace= <span style=\"color: #008000;\">True<\/span> )<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Se il tuo DataFrame ha nomi di colonna duplicati, puoi utilizzare la seguente sintassi per rimuovere una colonna in base al numero di indice:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define list of columns\n<\/span>cols = [x <span style=\"color: #008000;\">for<\/span> x <span style=\"color: #008000;\">in<\/span> range( <span style=\"color: #3366ff;\">df.shape<\/span> [1])]\n\n<span style=\"color: #008080;\">#drop second column\n<\/span>collars. <span style=\"color: #3366ff;\">remove<\/span> (1)\n\n<span style=\"color: #008080;\">#view resulting DataFrame\n<\/span>df. <span style=\"color: #3366ff;\">iloc<\/span> [:, cols]<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Gli esempi seguenti mostrano come eliminare in pratica le colonne in base all&#8217;indice.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 1: elimina una colonna per indice<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come rimuovere la prima colonna da 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]})<\/span>\n\n#drop first column from DataFrame<\/span>\ndf. <span style=\"color: #3366ff;\">drop<\/span> ( <span style=\"color: #3366ff;\">df.columns<\/span> [0], axis= <span style=\"color: #008000;\">1<\/span> , inplace= <span style=\"color: #008000;\">True<\/span> )\n\n<span style=\"color: #008080;\">#view resulting dataFrame<\/span>\ndf\n\n        first last points\n0 Dirk Nowitzki 26\n1 Kobe Bryant 31\n2 Tim Duncan 22\n3 LeBron James 29\n<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: eliminare pi\u00f9 colonne per indice<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come eliminare pi\u00f9 colonne 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]})<\/span>\n\n#drop first, second and fourth columns from DataFrame\n<\/span><span style=\"color: #000000;\">cols = [0, 1, 3] \n<\/span>df. <span style=\"color: #3366ff;\">drop<\/span> (df. <span style=\"color: #3366ff;\">columns<\/span> [cols], axis= <span style=\"color: #008000;\">1<\/span> , inplace= <span style=\"color: #008000;\">True<\/span> )\n\n<span style=\"color: #008080;\">#view resulting dataFrame<\/span>\ndf\n\n        last\n0 Nowitzki\n1 Bryant\n2 Duncan\n3 James\n<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 3: eliminare una colonna per indice con duplicati<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come rimuovere una colonna in base al numero di indice in un DataFrame panda quando esistono nomi di colonne duplicati:<\/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                   columns=[' <span style=\"color: #ff0000;\">team<\/span> ', ' <span style=\"color: #ff0000;\">last<\/span> ', ' <span style=\"color: #ff0000;\">last<\/span> ', ' <span style=\"color: #ff0000;\">points<\/span> '])\n\n<\/span>#define list of columns range\n<span style=\"color: #000000;\">cols = [x <span style=\"color: #008000;\">for<\/span> x <span style=\"color: #008000;\">in<\/span> range( <span style=\"color: #3366ff;\">df.shape<\/span> [1])]\n<\/span>\n#remove second column in DataFrame\n<span style=\"color: #000000;\">collars. <span style=\"color: #3366ff;\">remove<\/span> (1)\n<\/span>\n#view resulting DataFrame\n<span style=\"color: #000000;\">df. <span style=\"color: #3366ff;\">iloc<\/span> [:, cols]\n\n\tteam last points\n0 Mavs Nowitzki 26\n1 Lakers Bryant 31\n2 Spurs Duncan 22\n3 Cavs James 29\n<\/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-combinano-due-colonne\/\" target=\"_blank\" rel=\"noopener\">Come combinare due colonne in Pandas<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/i-panda-ordinano-le-colonne-per-nome\/\" target=\"_blank\" rel=\"noopener\">Panda: come ordinare le colonne per nome<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/differenza-dei-panda-tra-due-colonne\/\" target=\"_blank\" rel=\"noopener\">Panda: come trovare la differenza tra due colonne<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/colonna-somma-panda-con-condizione\/\" target=\"_blank\" rel=\"noopener\">Panda: come aggiungere colonne in base a una condizione<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare la seguente sintassi per rimuovere una colonna da un DataFrame panda in base al numero di indice: #drop first column from DataFrame df. drop ( df.columns [0], axis= 1 , inplace= True ) E puoi utilizzare la seguente sintassi per rimuovere pi\u00f9 colonne da un DataFrame panda in base ai numeri di [&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 le colonne per indice in Pandas \u2013 Stology<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come rimuovere una o pi\u00f9 colonne da un DataFrame panda in base al numero di indice, 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-colonna-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 le colonne per indice in Pandas \u2013 Stology\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come rimuovere una o pi\u00f9 colonne da un DataFrame panda in base al numero di indice, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/i-panda-rilasciano-colonna-per-indice\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-25T05:11:30+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-colonna-per-indice\/\",\"url\":\"https:\/\/statorials.org\/it\/i-panda-rilasciano-colonna-per-indice\/\",\"name\":\"Come eliminare le colonne per indice in Pandas \u2013 Stology\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-25T05:11:30+00:00\",\"dateModified\":\"2023-07-25T05:11:30+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come rimuovere una o pi\u00f9 colonne da un DataFrame panda in base al numero di indice, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/i-panda-rilasciano-colonna-per-indice\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/i-panda-rilasciano-colonna-per-indice\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/i-panda-rilasciano-colonna-per-indice\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come eliminare le colonne per indice in pandas\"}]},{\"@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 le colonne per indice in Pandas \u2013 Stology","description":"Questo tutorial spiega come rimuovere una o pi\u00f9 colonne da un DataFrame panda in base al numero di indice, 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-colonna-per-indice\/","og_locale":"it_IT","og_type":"article","og_title":"Come eliminare le colonne per indice in Pandas \u2013 Stology","og_description":"Questo tutorial spiega come rimuovere una o pi\u00f9 colonne da un DataFrame panda in base al numero di indice, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/i-panda-rilasciano-colonna-per-indice\/","og_site_name":"Statorials","article_published_time":"2023-07-25T05:11:30+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-colonna-per-indice\/","url":"https:\/\/statorials.org\/it\/i-panda-rilasciano-colonna-per-indice\/","name":"Come eliminare le colonne per indice in Pandas \u2013 Stology","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-25T05:11:30+00:00","dateModified":"2023-07-25T05:11:30+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come rimuovere una o pi\u00f9 colonne da un DataFrame panda in base al numero di indice, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/i-panda-rilasciano-colonna-per-indice\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/i-panda-rilasciano-colonna-per-indice\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/i-panda-rilasciano-colonna-per-indice\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come eliminare le colonne per indice in pandas"}]},{"@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\/1733"}],"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=1733"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/1733\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=1733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=1733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=1733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}