{"id":3318,"date":"2023-07-18T03:11:34","date_gmt":"2023-07-18T03:11:34","guid":{"rendered":"https:\/\/statorials.org\/it\/i-panda-sostituiscono-inf-con-max\/"},"modified":"2023-07-18T03:11:34","modified_gmt":"2023-07-18T03:11:34","slug":"i-panda-sostituiscono-inf-con-max","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/i-panda-sostituiscono-inf-con-max\/","title":{"rendered":"Panda: come sostituire inf con max value"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare i seguenti metodi per sostituire i valori <strong>inf<\/strong> e <strong>-inf<\/strong> con il valore massimo in un DataFrame panda:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: sostituisci inf con il valore massimo in una colonna<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#find max value of column\n<\/span>max_value = np. <span style=\"color: #3366ff;\">nanmax<\/span> (df[' <span style=\"color: #ff0000;\">my_column<\/span> '][df[' <span style=\"color: #ff0000;\">my_column<\/span> '] != np. <span style=\"color: #3366ff;\">inf<\/span> ])\n\n<span style=\"color: #008080;\">#replace inf and -inf in column with max value of column \n<\/span>df[' <span style=\"color: #ff0000;\">my_column<\/span> ']. <span style=\"color: #3366ff;\">replace<\/span> ([np. <span style=\"color: #3366ff;\">inf<\/span> , -np. <span style=\"color: #3366ff;\">inf<\/span> ], max_value, inplace= <span style=\"color: #008000;\">True<\/span> )\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: sostituisci inf con il valore massimo in tutte le colonne<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#find max value of entire data frame\n<span style=\"color: #000000;\">max_value = np. <span style=\"color: #3366ff;\">nanmax<\/span> (df[df != <span style=\"color: #3366ff;\">np.inf<\/span> ])\n<\/span>\n#replace inf and -inf in all columns with max value\n<span style=\"color: #000000;\">df. <span style=\"color: #3366ff;\">replace<\/span> ([np. <span style=\"color: #3366ff;\">inf<\/span> , -np. <span style=\"color: #3366ff;\">inf<\/span> ], max_value, inplace= <span style=\"color: #008000;\">True<\/span> )<\/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;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008000;\">import<\/span> pandas <span style=\"color: #008000;\">as<\/span> pd\n<span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n\n<span style=\"color: #008080;\">#createDataFrame\n<\/span>df = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">points<\/span> ': [18, np.inf, 19, np.inf, 14, 11, 20, 28],\n                   ' <span style=\"color: #ff0000;\">assists<\/span> ': [5, 7, 7, 9, 12, 9, 9, np.inf],\n                   ' <span style=\"color: #ff0000;\">rebounds<\/span> ': [np.inf, 8, 10, 6, 6, -np.inf, 9, 12]})\n\n<span style=\"color: #008080;\">#view DataFrame\n<\/span><span style=\"color: #008000;\">print<\/span> (df)\n\n   points assists rebounds\n0 18.0 5.0 lower\n1 lower 7.0 8.0\n2 19.0 7.0 10.0\n3 lower 9.0 6.0\n4 14.0 12.0 6.0\n5 11.0 9.0 -inf\n6 20.0 9.0 9.0\n7 28.0 lower 12.0\n<\/strong><\/span><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 1: sostituisci inf con il valore massimo in una colonna<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come sostituire i valori <strong>inf<\/strong> e <strong>-inf<\/strong> nella colonna rimbalzi con il valore massimo nella colonna rimbalzi:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#find max value of rebounds\n<\/span>max_value = np. <span style=\"color: #3366ff;\">nanmax<\/span> (df[' <span style=\"color: #ff0000;\">rebounds<\/span> '][df[' <span style=\"color: #ff0000;\">rebounds<\/span> '] != np. <span style=\"color: #3366ff;\">inf<\/span> ])\n\n<span style=\"color: #008080;\">#replace inf and -inf in rebounds with max value of rebounds\n<\/span>df[' <span style=\"color: #ff0000;\">rebounds<\/span> ']. <span style=\"color: #3366ff;\">replace<\/span> ([np. <span style=\"color: #3366ff;\">inf<\/span> , -np. <span style=\"color: #3366ff;\">inf<\/span> ], max_value, 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   points assists rebounds\n0 18.0 5.0 12.0\n1 lower 7.0 8.0\n2 19.0 7.0 10.0\n3 lower 9.0 6.0\n4 14.0 12.0 6.0\n5 11.0 9.0 12.0\n6 20.0 9.0 9.0\n7 28.0 lower 12.0<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che ogni valore <strong>inf<\/strong> e <strong>-inf<\/strong> nella colonna rimbalzi \u00e8 stato sostituito con il valore massimo in quella colonna pari a <strong>12<\/strong> .<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 2: sostituisci inf con il valore massimo in tutte le colonne<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come sostituire i valori <strong>inf<\/strong> e <strong>-inf<\/strong> di ciascuna colonna con il valore massimo dell&#8217;intero frame di dati:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#find max value of entire data frame\n<span style=\"color: #000000;\">max_value = np. <span style=\"color: #3366ff;\">nanmax<\/span> (df[df != <span style=\"color: #3366ff;\">np.inf<\/span> ])\n\n<span style=\"color: #008080;\">#replace all inf and -inf with max value\n<\/span>df. <span style=\"color: #3366ff;\">replace<\/span> ([np. <span style=\"color: #3366ff;\">inf<\/span> , -np. <span style=\"color: #3366ff;\">inf<\/span> ], max_value, 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   points assists rebounds\n0 18.0 5.0 28.0\n1 28.0 7.0 8.0\n2 19.0 7.0 10.0\n3 28.0 9.0 6.0\n4 14.0 12.0 6.0\n5 11.0 9.0 28.0\n6 20.0 9.0 9.0\n7 28.0 28.0 12.0\n<\/span><\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Si noti che ciascun valore <strong>inf<\/strong> e <strong>-inf<\/strong> in ciascuna colonna \u00e8 stato sostituito dal valore massimo nell&#8217;intero frame di dati di <strong>28<\/strong> .<\/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 attivit\u00e0 comuni nei panda:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/panda-imputa-i-valori-mancanti\/\" target=\"_blank\" rel=\"noopener\">Come imputare i valori mancanti nei panda<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/i-panda-contano-i-valori-mancanti\/\" target=\"_blank\" rel=\"noopener\">Come contare i valori mancanti nei panda<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/i-panda-si-riempiono-di-cattiveria\/\" target=\"_blank\" rel=\"noopener\">Come riempire i valori NaN con la media nei panda<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare i seguenti metodi per sostituire i valori inf e -inf con il valore massimo in un DataFrame panda: Metodo 1: sostituisci inf con il valore massimo in una colonna #find max value of column max_value = np. nanmax (df[&#8216; my_column &#8216;][df[&#8216; my_column &#8216;] != np. inf ]) #replace inf and -inf in [&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>Panda: come sostituire inf con Max Value \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come sostituire i valori inf e -inf con il valore massimo in un DataFrame panda, inclusi 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-sostituiscono-inf-con-max\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Panda: come sostituire inf con Max Value \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come sostituire i valori inf e -inf con il valore massimo in un DataFrame panda, inclusi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/i-panda-sostituiscono-inf-con-max\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-18T03:11:34+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-sostituiscono-inf-con-max\/\",\"url\":\"https:\/\/statorials.org\/it\/i-panda-sostituiscono-inf-con-max\/\",\"name\":\"Panda: come sostituire inf con Max Value \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-18T03:11:34+00:00\",\"dateModified\":\"2023-07-18T03:11:34+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come sostituire i valori inf e -inf con il valore massimo in un DataFrame panda, inclusi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/i-panda-sostituiscono-inf-con-max\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/i-panda-sostituiscono-inf-con-max\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/i-panda-sostituiscono-inf-con-max\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Panda: come sostituire inf con max value\"}]},{\"@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":"Panda: come sostituire inf con Max Value \u2013 Statorials","description":"Questo tutorial spiega come sostituire i valori inf e -inf con il valore massimo in un DataFrame panda, inclusi 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-sostituiscono-inf-con-max\/","og_locale":"it_IT","og_type":"article","og_title":"Panda: come sostituire inf con Max Value \u2013 Statorials","og_description":"Questo tutorial spiega come sostituire i valori inf e -inf con il valore massimo in un DataFrame panda, inclusi esempi.","og_url":"https:\/\/statorials.org\/it\/i-panda-sostituiscono-inf-con-max\/","og_site_name":"Statorials","article_published_time":"2023-07-18T03:11:34+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-sostituiscono-inf-con-max\/","url":"https:\/\/statorials.org\/it\/i-panda-sostituiscono-inf-con-max\/","name":"Panda: come sostituire inf con Max Value \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-18T03:11:34+00:00","dateModified":"2023-07-18T03:11:34+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come sostituire i valori inf e -inf con il valore massimo in un DataFrame panda, inclusi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/i-panda-sostituiscono-inf-con-max\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/i-panda-sostituiscono-inf-con-max\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/i-panda-sostituiscono-inf-con-max\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Panda: come sostituire inf con max value"}]},{"@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\/3318"}],"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=3318"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3318\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}