{"id":2356,"date":"2023-07-22T15:28:02","date_gmt":"2023-07-22T15:28:02","guid":{"rendered":"https:\/\/statorials.org\/it\/rbind-in-pitone\/"},"modified":"2023-07-22T15:28:02","modified_gmt":"2023-07-22T15:28:02","slug":"rbind-in-pitone","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/rbind-in-pitone\/","title":{"rendered":"Come usare rbind in python (equivalente a r)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">La funzione <strong>rbind<\/strong> in R, abbreviazione di <em>row-bind<\/em> , pu\u00f2 essere utilizzata per combinare insieme i frame di dati in base alle loro righe.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Possiamo usare la funzione pandas <a href=\"https:\/\/pandas.pydata.org\/docs\/reference\/api\/pandas.concat.html\" target=\"_blank\" rel=\"noopener\">concat()<\/a> per eseguire la funzione equivalente in Python:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>df3 = pd. <span style=\"color: #3366ff;\">concat<\/span> ([df1, df2])\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">I seguenti esempi mostrano come utilizzare questa funzione nella pratica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 1: utilizzare rbind in Python con colonne uguali<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di avere i seguenti due DataFrames 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;\">#define DataFrames\n<span style=\"color: #000000;\">df1 = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">team<\/span> ': ['A', 'B', 'C', 'D', 'E'],\n                    ' <span style=\"color: #ff0000;\">points<\/span> ': [99, 91, 104, 88, 108]})\n\n<span style=\"color: #008000;\">print<\/span> (df1)\n\n  team points\n0 to 99\n1 B 91\n2 C 104\n3 D 88\n4 E 108\n\ndf2 = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">assists<\/span> ': ['F', 'G', 'H', 'I', 'J'],\n                    ' <span style=\"color: #ff0000;\">rebounds<\/span> ': [91, 88, 85, 87, 95]})\n\n<span style=\"color: #008000;\">print<\/span> (df2)\n\n  team points\n0 F 91\n1 G 88\n2:85\n3 I 87\n4 days 95\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo usare la funzione <strong>concat()<\/strong> per collegare rapidamente questi due DataFrame tramite le loro linee:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#row-bind two DataFrames\n<span style=\"color: #000000;\">df3 = pd. <span style=\"color: #3366ff;\">concat<\/span> ([df1, df2])\n\n<span style=\"color: #008080;\">#view resulting DataFrame\n<\/span>df3\n\n\tteam points\n0 to 99\n1 B 91\n2 C 104\n3 D 88\n4 E 108\n0 F 91\n1 G 88\n2:85\n3 I 87\n4 days 95\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che possiamo anche utilizzare <strong>reset_index()<\/strong> per reimpostare i valori dell&#8217;indice del nuovo DataFrame:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#row-bind two DataFrames and reset index values\n<span style=\"color: #000000;\">df3 = pd. <span style=\"color: #3366ff;\">concat<\/span> ([df1, df2]). <span style=\"color: #3366ff;\">reset_index<\/span> (drop= <span style=\"color: #008000;\">True<\/span> )\n\n<span style=\"color: #008080;\">#view resulting DataFrame\n<\/span>df3\n\n\tteam points\n0 to 99\n1 B 91\n2 C 104\n3 D 88\n4 E 108\n5 F 91\n6 G 88\n7:85 a.m.\n8 I 87\n9 D 95<\/span><\/span><\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: utilizzo di rbind in Python con colonne non uguali<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Possiamo anche utilizzare la funzione <strong>concat()<\/strong> per collegare insieme due DataFrame che hanno un numero di colonne diverso ed eventuali valori mancanti verranno semplicemente riempiti con NaN:<\/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 DataFrames\n<span style=\"color: #000000;\">df1 = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">team<\/span> ': ['A', 'B', 'C', 'D', 'E'],\n                    ' <span style=\"color: #ff0000;\">points<\/span> ': [99, 91, 104, 88, 108]})\n\ndf2 = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">team<\/span> ': ['F', 'G', 'H', 'I', 'J'],\n                    ' <span style=\"color: #ff0000;\">points<\/span> ': [91, 88, 85, 87, 95],\n                    ' <span style=\"color: #ff0000;\">rebounds<\/span> ': [24, 27, 27, 30, 35]})<\/span>\n\n#row-bind two DataFrames\n<span style=\"color: #000000;\">df3 = pd. <span style=\"color: #3366ff;\">concat<\/span> ([df1, df2]). <span style=\"color: #3366ff;\">reset_index<\/span> (drop= <span style=\"color: #008000;\">True<\/span> )\n<\/span>\n#view resulting DataFrame\n<span style=\"color: #000000;\">df3\n\n\tteam points rebounds\n0 to 99 NaN\n1 B 91 NaN\n2 C 104 NaN\n3 D 88 NaN\n4 E 108 NaN\n5 F 91 24.0\n6G 88 27.0\n7:85 AM 27.0\n8 I 87 30.0\n9 D 95 35.0<\/span><\/span><\/strong><\/pre>\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 funzioni comuni in Python:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/cbind-in-python\/\" target=\"_blank\" rel=\"noopener\">Come usare cbind in Python (equivalente a R)<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/ricerca-del-panda\/\" target=\"_blank\" rel=\"noopener\">Come eseguire una CERCA.VERT in Panda<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/i-panda-rilasciano-righe-con-valore\/\" target=\"_blank\" rel=\"noopener\">Come eliminare righe contenenti un valore specifico in Pandas<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>La funzione rbind in R, abbreviazione di row-bind , pu\u00f2 essere utilizzata per combinare insieme i frame di dati in base alle loro righe. Possiamo usare la funzione pandas concat() per eseguire la funzione equivalente in Python: df3 = pd. concat ([df1, df2]) I seguenti esempi mostrano come utilizzare questa funzione nella pratica. Esempio 1: [&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 usare rbind in Python (equivalente a R) \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come associare due DataFrame insieme in Python, il che equivale a utilizzare la funzione rbind in R.\" \/>\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\/rbind-in-pitone\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come usare rbind in Python (equivalente a R) \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come associare due DataFrame insieme in Python, il che equivale a utilizzare la funzione rbind in R.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/rbind-in-pitone\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-22T15:28:02+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\/rbind-in-pitone\/\",\"url\":\"https:\/\/statorials.org\/it\/rbind-in-pitone\/\",\"name\":\"Come usare rbind in Python (equivalente a R) \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-22T15:28:02+00:00\",\"dateModified\":\"2023-07-22T15:28:02+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come associare due DataFrame insieme in Python, il che equivale a utilizzare la funzione rbind in R.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/rbind-in-pitone\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/rbind-in-pitone\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/rbind-in-pitone\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come usare rbind in python (equivalente a r)\"}]},{\"@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 usare rbind in Python (equivalente a R) \u2013 Statorials","description":"Questo tutorial spiega come associare due DataFrame insieme in Python, il che equivale a utilizzare la funzione rbind in R.","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\/rbind-in-pitone\/","og_locale":"it_IT","og_type":"article","og_title":"Come usare rbind in Python (equivalente a R) \u2013 Statorials","og_description":"Questo tutorial spiega come associare due DataFrame insieme in Python, il che equivale a utilizzare la funzione rbind in R.","og_url":"https:\/\/statorials.org\/it\/rbind-in-pitone\/","og_site_name":"Statorials","article_published_time":"2023-07-22T15:28:02+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\/rbind-in-pitone\/","url":"https:\/\/statorials.org\/it\/rbind-in-pitone\/","name":"Come usare rbind in Python (equivalente a R) \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-22T15:28:02+00:00","dateModified":"2023-07-22T15:28:02+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come associare due DataFrame insieme in Python, il che equivale a utilizzare la funzione rbind in R.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/rbind-in-pitone\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/rbind-in-pitone\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/rbind-in-pitone\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come usare rbind in python (equivalente a r)"}]},{"@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\/2356"}],"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=2356"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2356\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=2356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=2356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=2356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}