{"id":2205,"date":"2023-07-23T06:40:16","date_gmt":"2023-07-23T06:40:16","guid":{"rendered":"https:\/\/statorials.org\/it\/indice-di-ripristino-dei-panda\/"},"modified":"2023-07-23T06:40:16","modified_gmt":"2023-07-23T06:40:16","slug":"indice-di-ripristino-dei-panda","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/indice-di-ripristino-dei-panda\/","title":{"rendered":"Come reimpostare un indice in pandas dataframe (con esempi)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare la seguente sintassi per reimpostare un indice in un DataFrame panda:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>df. <span style=\"color: #3366ff;\">reset_index<\/span> (drop= <span style=\"color: #008000;\">True<\/span> , place= <span style=\"color: #008000;\">True<\/span> )\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Nota i seguenti argomenti:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>drop<\/strong> : specificando <strong>True<\/strong> impedisce ai panda di salvare l&#8217;indice originale come colonna nel DataFrame.<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>inplace<\/strong> : specificando <strong>True<\/strong> consente ai panda di sostituire l&#8217;indice nel DataFrame originale invece di creare una copia del DataFrame.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Gli esempi seguenti mostrano come utilizzare questa sintassi nella pratica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 1: reimpostare l&#8217;indice ed eliminare il vecchio indice<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di avere i seguenti panda DataFrame:<\/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;\">#define DataFrame\n<span style=\"color: #000000;\">df = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">points<\/span> ': [25, 12, 15, 14, 19, 23, 25, 29],\n                   ' <span style=\"color: #ff0000;\">assists<\/span> ': [5, 7, 7, 9, 12, 9, 9, 4],\n                   ' <span style=\"color: #ff0000;\">rebounds<\/span> ': [11, 8, 10, 6, 6, 5, 9, 12]},\n                   index=[0, 4, 3, 5, 2, 1, 7, 6])\n\n<span style=\"color: #008080;\">#view DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n   points assists rebounds\n0 25 5 11\n4 12 7 8\n3 15 7 10\n5 14 9 6\n2 19 12 6\n1 23 9 5\n7 25 9 9\n6 29 4 12\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come reimpostare l&#8217;indice di DataFrame e rimuovere completamente il vecchio indice:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#reset indexes\n<\/span>df. <span style=\"color: #3366ff;\">reset_index<\/span> (drop= <span style=\"color: #008000;\">True<\/span> , place= <span style=\"color: #008000;\">True<\/span> )\n\n<span style=\"color: #008080;\">#view updated DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n   points assists rebounds\n0 25 5 11\n1 12 7 8\n2 15 7 10\n3 14 9 6\n4 19 12 6\n5 23 9 5\n6 25 9 9\n7 29 4 12<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che l&#8217;indice \u00e8 stato reimpostato e i valori dell&#8217;indice ora vanno da 0 a 7.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: reimpostare l&#8217;indice e mantenere il vecchio indice come colonna<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di avere i seguenti panda DataFrame:<\/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;\">#define DataFrame\n<span style=\"color: #000000;\">df = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">points<\/span> ': [25, 12, 15, 14, 19, 23, 25, 29],\n                   ' <span style=\"color: #ff0000;\">assists<\/span> ': [5, 7, 7, 9, 12, 9, 9, 4],\n                   ' <span style=\"color: #ff0000;\">rebounds<\/span> ': [11, 8, 10, 6, 6, 5, 9, 12]},\n                   index=['A', 'C', 'D', 'B', 'E', 'G', 'F', 'H'])\n\n<span style=\"color: #008080;\">#view DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n   points assists rebounds\nA 25 5 11\nC 12 7 8\nD 15 7 10\nB 14 9 6\nE 19 12 6\nG 23 9 5\nF 25 9 9\nH 29 4 12\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come reimpostare l&#8217;indice del DataFrame e mantenere il vecchio indice come colonna nel DataFrame:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#reset index and retain old index as a column\n<\/span>df. <span style=\"color: #3366ff;\">reset_index<\/span> (inplace= <span style=\"color: #008000;\">True<\/span> )\n\n<span style=\"color: #008080;\">#view updated DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n  index points assists rebounds\n0 to 25 5 11\n1 C 12 7 8\n2 D 15 7 10\n3 B 14 9 6\n4 E 19 12 6\n5G 23 9 5\n6 F 25 9 9\n7:29 4 12<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che l&#8217;indice \u00e8 stato reimpostato e i valori dell&#8217;indice ora vanno da 0 a 7.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Si noti inoltre che il vecchio indice (con le lettere) viene conservato come una nuova colonna nel DataFrame chiamata &#8220;indice&#8221;.<\/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-convertono-lindice-in-colonna\/\" target=\"_blank\" rel=\"noopener\">Come convertire l&#8217;indice in colonna in Pandas<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/i-panda-impostano-la-colonna-come-indice\/\" target=\"_blank\" rel=\"noopener\">Come impostare la colonna come indice in Pandas<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/rinominare-lindice-dei-panda\/\" target=\"_blank\" rel=\"noopener\">Come rinominare l&#8217;indice in Pandas<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare la seguente sintassi per reimpostare un indice in un DataFrame panda: df. reset_index (drop= True , place= True ) Nota i seguenti argomenti: drop : specificando True impedisce ai panda di salvare l&#8217;indice originale come colonna nel DataFrame. inplace : specificando True consente ai panda di sostituire l&#8217;indice nel DataFrame originale invece [&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 reimpostare un indice in Pandas DataFrame (con esempi) - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come reimpostare un 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\/indice-di-ripristino-dei-panda\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come reimpostare un indice in Pandas DataFrame (con esempi) - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come reimpostare un indice in un DataFrame panda, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/indice-di-ripristino-dei-panda\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-23T06:40:16+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\/indice-di-ripristino-dei-panda\/\",\"url\":\"https:\/\/statorials.org\/it\/indice-di-ripristino-dei-panda\/\",\"name\":\"Come reimpostare un indice in Pandas DataFrame (con esempi) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-23T06:40:16+00:00\",\"dateModified\":\"2023-07-23T06:40:16+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come reimpostare un indice in un DataFrame panda, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/indice-di-ripristino-dei-panda\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/indice-di-ripristino-dei-panda\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/indice-di-ripristino-dei-panda\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come reimpostare un indice in pandas dataframe (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 reimpostare un indice in Pandas DataFrame (con esempi) - Statorials","description":"Questo tutorial spiega come reimpostare un 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\/indice-di-ripristino-dei-panda\/","og_locale":"it_IT","og_type":"article","og_title":"Come reimpostare un indice in Pandas DataFrame (con esempi) - Statorials","og_description":"Questo tutorial spiega come reimpostare un indice in un DataFrame panda, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/indice-di-ripristino-dei-panda\/","og_site_name":"Statorials","article_published_time":"2023-07-23T06:40:16+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\/indice-di-ripristino-dei-panda\/","url":"https:\/\/statorials.org\/it\/indice-di-ripristino-dei-panda\/","name":"Come reimpostare un indice in Pandas DataFrame (con esempi) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-23T06:40:16+00:00","dateModified":"2023-07-23T06:40:16+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come reimpostare un indice in un DataFrame panda, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/indice-di-ripristino-dei-panda\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/indice-di-ripristino-dei-panda\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/indice-di-ripristino-dei-panda\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come reimpostare un indice in pandas dataframe (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\/2205"}],"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=2205"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2205\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=2205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=2205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=2205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}