{"id":1928,"date":"2023-07-24T10:24:52","date_gmt":"2023-07-24T10:24:52","guid":{"rendered":"https:\/\/statorials.org\/it\/i-panda-eseguono-literazione-sulle-colonne-del-dataframe\/"},"modified":"2023-07-24T10:24:52","modified_gmt":"2023-07-24T10:24:52","slug":"i-panda-eseguono-literazione-sulle-colonne-del-dataframe","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/i-panda-eseguono-literazione-sulle-colonne-del-dataframe\/","title":{"rendered":"Come scorrere le colonne in pandas dataframe"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare la seguente sintassi di base per scorrere le colonne di un DataFrame panda:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">for <span style=\"color: #000000;\">name, values <span style=\"color: #008000;\">in<\/span> df. <span style=\"color: #3366ff;\">iteritems<\/span> ():\n  <span style=\"color: #993300;\">print<\/span> (values)\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">I seguenti esempi mostrano come utilizzare questa sintassi in pratica con i seguenti DataFrame panda:<\/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;\">#createDataFrame\n<\/span>df = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">points<\/span> ': [25, 12, 15, 14, 19],\n                   ' <span style=\"color: #ff0000;\">assists<\/span> ': [5, 7, 7, 9, 12],\n                   ' <span style=\"color: #ff0000;\">rebounds<\/span> ': [11, 8, 10, 6, 6]})\n\n<span style=\"color: #008080;\">#view DataFrame\n<\/span>df\n\n\tpoints assists rebounds\n0 25 5 11\n1 12 7 8\n2 15 7 10\n3 14 9 6\n4 19 12 6\n<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 1: scorrere tutte le colonne di DataFrame<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come scorrere ciascuna colonna di un DataFrame panda:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">for <span style=\"color: #000000;\">name, values <span style=\"color: #008000;\">in<\/span> df. <span style=\"color: #3366ff;\">iteritems<\/span> ():\n<span style=\"color: #993300;\">print<\/span> (values)<\/span><\/span>\n\n0 25\n1 12\n2 15\n3 14\n4 19\nName: points, dtype: int64\n0 5\n1 7\n2 7\n3 9\n4 12\nName: assists, dtype: int64\n0 11\n1 8\n2 10\n3 6\n4 6\nName: rebounds, dtype: int64<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo anche utilizzare la seguente sintassi per scorrere ciascuna colonna e stampare solo i nomi delle colonne:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">for <span style=\"color: #000000;\">name, values <span style=\"color: #008000;\">in<\/span> df. <span style=\"color: #3366ff;\">iteritems<\/span> ():\n<span style=\"color: #993300;\">print<\/span> (name)\n\npoints\nassists\nrebounds\n<\/span><\/span><\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: scorrere su colonne specifiche<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">La seguente sintassi mostra come scorrere colonne specifiche in un DataFrame panda:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">for<\/span> name, values <span style=\"color: #008000;\">in<\/span> df[[' <span style=\"color: #ff0000;\">points<\/span> ', ' <span style=\"color: #ff0000;\">rebounds<\/span> ']]. <span style=\"color: #3366ff;\">iteritems<\/span> ():\n  <span style=\"color: #993300;\">print<\/span> (values)\n\n0 25\n1 12\n2 15\n3 14\n4 19\nName: points, dtype: int64\n0 11\n1 8\n2 10\n3 6\n4 6\nName: rebounds, dtype: int64\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo anche utilizzare la seguente sintassi per scorrere un intervallo di colonne specifiche:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">for<\/span> name, values <span style=\"color: #008000;\">in <span style=\"color: #000000;\">df. <span style=\"color: #3366ff;\">iloc<\/span> [:, 0:2]<\/span><\/span> . <span style=\"color: #3366ff;\">iteritems<\/span> ():\n  <span style=\"color: #993300;\">print<\/span> (values)\n\n0 25\n1 12\n2 15\n3 14\n4 19\nName: points, dtype: int64\n0 5\n1 7\n2 7\n3 9\n4 12\nName: assists, dtype: int64\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Puoi trovare la documentazione completa per la funzione <strong>iteritems()<\/strong> <a href=\"https:\/\/pandas.pydata.org\/docs\/reference\/api\/pandas.DataFrame.iteritems.html\" target=\"_blank\" rel=\"noopener\">qui<\/a> .<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h3>\n<p> Come applicare una funzione alle colonne selezionate in Pandas<br \/> <a href=\"https:\/\/statorials.org\/it\/i-panda-cambiano-lordine-delle-colonne\/\" target=\"_blank\" rel=\"noopener\">Come modificare l&#8217;ordine delle colonne in Pandas<\/a><br \/> <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><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare la seguente sintassi di base per scorrere le colonne di un DataFrame panda: for name, values in df. iteritems (): print (values) I seguenti esempi mostrano come utilizzare questa sintassi in pratica con i seguenti DataFrame panda: import pandas as pd #createDataFrame df = pd. DataFrame ({&#8216; points &#8216;: [25, 12, 15, [&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 scorrere le colonne in Pandas DataFrame - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come scorrere le colonne di 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-eseguono-literazione-sulle-colonne-del-dataframe\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come scorrere le colonne in Pandas DataFrame - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come scorrere le colonne di un DataFrame panda, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/i-panda-eseguono-literazione-sulle-colonne-del-dataframe\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-24T10:24:52+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=\"1 minuto\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/i-panda-eseguono-literazione-sulle-colonne-del-dataframe\/\",\"url\":\"https:\/\/statorials.org\/it\/i-panda-eseguono-literazione-sulle-colonne-del-dataframe\/\",\"name\":\"Come scorrere le colonne in Pandas DataFrame - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-24T10:24:52+00:00\",\"dateModified\":\"2023-07-24T10:24:52+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come scorrere le colonne di un DataFrame panda, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/i-panda-eseguono-literazione-sulle-colonne-del-dataframe\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/i-panda-eseguono-literazione-sulle-colonne-del-dataframe\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/i-panda-eseguono-literazione-sulle-colonne-del-dataframe\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come scorrere le colonne in pandas dataframe\"}]},{\"@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 scorrere le colonne in Pandas DataFrame - Statorials","description":"Questo tutorial spiega come scorrere le colonne di 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-eseguono-literazione-sulle-colonne-del-dataframe\/","og_locale":"it_IT","og_type":"article","og_title":"Come scorrere le colonne in Pandas DataFrame - Statorials","og_description":"Questo tutorial spiega come scorrere le colonne di un DataFrame panda, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/i-panda-eseguono-literazione-sulle-colonne-del-dataframe\/","og_site_name":"Statorials","article_published_time":"2023-07-24T10:24:52+00:00","author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"1 minuto"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/i-panda-eseguono-literazione-sulle-colonne-del-dataframe\/","url":"https:\/\/statorials.org\/it\/i-panda-eseguono-literazione-sulle-colonne-del-dataframe\/","name":"Come scorrere le colonne in Pandas DataFrame - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-24T10:24:52+00:00","dateModified":"2023-07-24T10:24:52+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come scorrere le colonne di un DataFrame panda, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/i-panda-eseguono-literazione-sulle-colonne-del-dataframe\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/i-panda-eseguono-literazione-sulle-colonne-del-dataframe\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/i-panda-eseguono-literazione-sulle-colonne-del-dataframe\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come scorrere le colonne in pandas dataframe"}]},{"@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\/1928"}],"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=1928"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/1928\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=1928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=1928"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=1928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}