{"id":3530,"date":"2023-07-17T00:25:03","date_gmt":"2023-07-17T00:25:03","guid":{"rendered":"https:\/\/statorials.org\/it\/panda-che-rotolano-al-massimo\/"},"modified":"2023-07-17T00:25:03","modified_gmt":"2023-07-17T00:25:03","slug":"panda-che-rotolano-al-massimo","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/panda-che-rotolano-al-massimo\/","title":{"rendered":"Come calcolare un massimo mobile nei panda (con esempi)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare i seguenti metodi per calcolare un valore massimo mobile in un DataFrame panda:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: calcolare il massimo scorrevole<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>df[' <span style=\"color: #ff0000;\">rolling_max<\/span> '] = df. <span style=\"color: #3366ff;\">values_column<\/span> . <span style=\"color: #3366ff;\">cummax<\/span> ()<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: calcolare il massimo scorrevole per gruppo<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>df[' <span style=\"color: #ff0000;\">rolling_max<\/span> '] = df. <span style=\"color: #3366ff;\">groupby<\/span> (' <span style=\"color: #ff0000;\">group_column<\/span> '). <span style=\"color: #3366ff;\">values_column<\/span> . <span style=\"color: #3366ff;\">cummax<\/span> ()\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Gli esempi seguenti mostrano come utilizzare ciascun metodo nella pratica.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 1: calcolare il massimo scorrevole<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Supponiamo di avere il seguente DataFrame panda che mostra le vendite effettuate ogni giorno in un negozio:<\/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<\/span>\ndf = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">day<\/span> ': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],\n                   ' <span style=\"color: #ff0000;\">sales<\/span> ': [4, 6, 5, 8, 14, 13, 13, 12, 9, 8, 19, 14]})\n\n<span style=\"color: #008080;\">#view DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n    day sales\n0 1 4\n1 2 6\n2 3 5\n3 4 8\n4 5 14\n5 6 13\n6 7 13\n7 8 12\n8 9 9\n9 10 8\n10 11 19\n11 12 14\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare la seguente sintassi per creare una nuova colonna che visualizza il valore massimo delle vendite mobili:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#add column that displays rolling maximum of sales\n<\/span>df[' <span style=\"color: #ff0000;\">rolling_max<\/span> '] = df. <span style=\"color: #3366ff;\">dirty<\/span> . <span style=\"color: #3366ff;\">cummax<\/span> ()\n\n<span style=\"color: #008080;\">#view updated DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n    day sales rolling_max\n0 1 4 4\n1 2 6 6\n2 3 5 6\n3 4 8 8\n4 5 14 14\n5 6 13 14\n6 7 13 14\n7 8 12 14\n8 9 9 14\n9 10 8 14\n10 11 19 19\n11 12 14 19<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">La nuova colonna intitolata <strong>Rolling_max<\/strong> mostra il valore massimo mobile delle vendite.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 2:<\/strong><\/span> <span style=\"color: #000000;\"><strong>calcolare il massimo scorrevole per gruppo<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Supponiamo di avere il seguente DataFrame panda che mostra le vendite effettuate ogni giorno in due negozi diversi:<\/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<\/span>\ndf = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">store<\/span> ': ['A', 'A', 'A', 'A', 'A', 'A',\n                             'B', 'B', 'B', 'B', 'B', 'B'],\n                   ' <span style=\"color: #ff0000;\">day<\/span> ': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],\n                   ' <span style=\"color: #ff0000;\">sales<\/span> ': [4, 6, 5, 8, 14, 13, 13, 12, 9, 8, 19, 14]})\n\n<span style=\"color: #008080;\">#view DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n   store day sales\n0 to 1 4\n1 to 2 6\n2 to 3 5\n3 to 4 8\n4 to 5 14\n5 to 6 13\n6 B 7 13\n7 B 8 12\n8 B 9 9\n9 B 10 8\n10 B 11 19\n11 B 12 14\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare la seguente sintassi per creare una nuova colonna che visualizza il valore massimo delle vendite raggruppate per negozio:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#add column that displays rolling maximum of sales grouped by store\n<\/span>df[' <span style=\"color: #ff0000;\">rolling_max<\/span> '] = df. <span style=\"color: #3366ff;\">groupby<\/span> (' <span style=\"color: #ff0000;\">store<\/span> '). <span style=\"color: #3366ff;\">dirty<\/span> . <span style=\"color: #3366ff;\">cummax<\/span> ()\n\n<span style=\"color: #008080;\">#view updated DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n   store day sales rolling_max\n0 A 1 4 4\n1 to 2 6 6\n2 to 3 5 6\n3 to 4 8 8\n4 to 5 14 14\n5 to 6 13 14\n6 B 7 13 13\n7 B 8 12 13\n8 B 9 9 13\n9 B 10 8 13\n10 B 11 19 19\n11 B 12 14 19<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">La nuova colonna intitolata <strong>Rolling_max<\/strong> mostra il valore massimo mobile delle vendite, raggruppato per negozio.<\/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 operazioni comuni nei panda:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/i-panda-rilasciano-file-con-condizione\/\" target=\"_blank\" rel=\"noopener\">Come eliminare le righe in Pandas DataFrame in base alle condizioni<\/a><br \/><a href=\"https:\/\/statorials.org\/it\/i-panda-filtrano-piu-condizioni\/\" target=\"_blank\" rel=\"noopener\">Come filtrare un Pandas DataFrame su pi\u00f9 condizioni<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/panda-assenti\/\" target=\"_blank\" rel=\"noopener\">Come utilizzare il filtro &#8220;NOT IN&#8221; in Pandas DataFrame<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare i seguenti metodi per calcolare un valore massimo mobile in un DataFrame panda: Metodo 1: calcolare il massimo scorrevole df[&#8216; rolling_max &#8216;] = df. values_column . cummax () Metodo 2: calcolare il massimo scorrevole per gruppo df[&#8216; rolling_max &#8216;] = df. groupby (&#8216; group_column &#8216;). values_column . cummax () Gli esempi seguenti [&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 calcolare un massimo scorrevole nei panda (con esempi) - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come calcolare il valore massimo mobile nei 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\/panda-che-rotolano-al-massimo\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come calcolare un massimo scorrevole nei panda (con esempi) - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come calcolare il valore massimo mobile nei panda, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/panda-che-rotolano-al-massimo\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-17T00:25:03+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\/panda-che-rotolano-al-massimo\/\",\"url\":\"https:\/\/statorials.org\/it\/panda-che-rotolano-al-massimo\/\",\"name\":\"Come calcolare un massimo scorrevole nei panda (con esempi) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-17T00:25:03+00:00\",\"dateModified\":\"2023-07-17T00:25:03+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come calcolare il valore massimo mobile nei panda, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/panda-che-rotolano-al-massimo\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/panda-che-rotolano-al-massimo\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/panda-che-rotolano-al-massimo\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come calcolare un massimo mobile nei 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 calcolare un massimo scorrevole nei panda (con esempi) - Statorials","description":"Questo tutorial spiega come calcolare il valore massimo mobile nei 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\/panda-che-rotolano-al-massimo\/","og_locale":"it_IT","og_type":"article","og_title":"Come calcolare un massimo scorrevole nei panda (con esempi) - Statorials","og_description":"Questo tutorial spiega come calcolare il valore massimo mobile nei panda, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/panda-che-rotolano-al-massimo\/","og_site_name":"Statorials","article_published_time":"2023-07-17T00:25:03+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\/panda-che-rotolano-al-massimo\/","url":"https:\/\/statorials.org\/it\/panda-che-rotolano-al-massimo\/","name":"Come calcolare un massimo scorrevole nei panda (con esempi) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-17T00:25:03+00:00","dateModified":"2023-07-17T00:25:03+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come calcolare il valore massimo mobile nei panda, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/panda-che-rotolano-al-massimo\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/panda-che-rotolano-al-massimo\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/panda-che-rotolano-al-massimo\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come calcolare un massimo mobile nei 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\/3530"}],"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=3530"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3530\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3530"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3530"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}