{"id":8212,"date":"2025-05-16T07:17:30","date_gmt":"2025-05-16T07:17:30","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=8212"},"modified":"2025-05-19T06:06:32","modified_gmt":"2025-05-19T06:06:32","slug":"how-to-merge-and-join-pandas-dataframes","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/","title":{"rendered":"How to Merge and Join Pandas Dataframes"},"content":{"rendered":"\n<p>Pandas dataframe makes it easy to store and analyze data as tables using rows and columns. They support tons of functions and operations simplifying <a href=\"https:\/\/ubiq.co\/tools\/data-reporting\">data analysis and reporting<\/a>. Sometimes, Python developers need to merge and join Pandas dataframes. In this article, we will learn the different ways to do this.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#How_to_Merge_and_Join_Pandas_Dataframes\" >How to Merge and Join Pandas Dataframes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#1_Concatenate_Dataframe\" >1. Concatenate Dataframe<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#Using_concat\" >Using concat<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#By_specifying_type_of_concatenation\" >By specifying type of concatenation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#By_ignoring_indexes\" >By ignoring indexes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#Using_group_of_keys\" >Using group of keys<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#2_Merge_Dataframe\" >2. Merge Dataframe<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#Based_on_one_or_more_keys\" >Based on one or more keys<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#By_specifying_type_of_merge\" >By specifying type of merge<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#3_Join_Dataframe\" >3. Join Dataframe<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#Using_join\" >Using join()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#Using_how_argument\" >Using how argument<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Merge_and_Join_Pandas_Dataframes\"><\/span>How to Merge and Join Pandas Dataframes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are the different ways to merge and join pandas dataframes, using concat(), merge( ) and join() functions. Let us say you have the following two dataframes to work with.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import pandas as pd<br><br>d1 = {'Name': ['John','Jim','Tim'],<br>         'Age': [27, 24, 22],<br>         'City': ['NYC', 'San Francisco','London'],<br>     }<br><br>d2 = {'Name': ['Jane','Jessica','Tess'],<br>         'Age': [25, 34, 32],<br>         'City': ['Chicago', 'Los Angeles','Philadelphia'],<br>     }<br>     <br>df1 = pd.DataFrame(d1, index=[0, 1, 2])<br><br>df2 = pd.DataFrame(d2, index=[2, 3, 4])<br><br>print(df1)<br>print(df2)<br><br>## output<br><br>   Name  Age           City<br>0  John   27            NYC<br>1   Jim   24  San Francisco<br>2   Tim   22         London<br><br>      Name  Age          City<br>2     Jane   25       Chicago<br>3  Jessica   34   Los Angeles<br>4     Tess   32  Philadelphia<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Concatenate_Dataframe\"><\/span>1. Concatenate Dataframe<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_concat\"><\/span>Using concat<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Pandas library supports concat() function that allows you to concatenate 2 or more dataframes by passing a list of dataframes as argument. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pd.concat([df1, df2, ...])<\/pre>\n\n\n\n<p>It returns a new concatenated dataframe that can be stored as a separate dataframe or be used to overwrite one of the original dataframes.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">res = pd.concat([df1,df2])<br>print(res)<br><br>## output<br><br>      Name  Age           City<br>0     John   27            NYC<br>1      Jim   24  San Francisco<br>2      Tim   22         London<br>2     Jane   25        Chicago<br>3  Jessica   34    Los Angeles<br>4     Tess   32   Philadelphia<\/pre>\n\n\n\n<p>In this approach, if you end up with duplicate rows or column values, then you can easily <a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-find-duplicates-in-python-pandas-dataframe\/\">find duplicates<\/a> using duplicated() function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"By_specifying_type_of_concatenation\"><\/span>By specifying type of concatenation<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Concat() function allows you to perform different types of joins such as inner joins and outer joins. You can do this by using axis and join arguments. This is similar to <a href=\"https:\/\/www.w3schools.com\/Sql\/sql_join.asp\" target=\"_blank\" rel=\"noreferrer noopener\">SQL joins<\/a> where the columns of two tables are combined side by side, using common column values, to create a larger table. In this case, the dataframe rows are not added one below the other, but one beside the other.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">res = pd.concat([df1,df2], axis=1, join='inner')<br>print(res)<br><br>## output<br><br>  Name  Age    City  Name  Age     City<br>2  Tim   22  London  Jane   25  Chicago<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"By_ignoring_indexes\"><\/span>By ignoring indexes<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>As seen above, by default, the result dataframe&#8217;s index values are borrowed from the original dataframes. But if you want the result dataframe to have a new set of indexes, you can use ignore_index option.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">res = pd.concat([df1,df2], ignore_index=True)<br>print(res)<br><br>## output<br><br>      Name  Age           City<br>0     John   27            NYC<br>1      Jim   24  San Francisco<br>2      Tim   22         London<br>3     Jane   25        Chicago<br>4  Jessica   34    Los Angeles<br>5     Tess   32   Philadelphia<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_group_of_keys\"><\/span>Using group of keys<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>While concatenating dataframe, you can also assign group keys to groups of rows belonging to each dataframe. You can do this using keys argument, as shown.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">res = pd.concat([df1,df2], <strong>keys = ['x','y']<\/strong>)<br>print(res)<br><br>## output<br><br>        Name  Age           City<br>x 0     John   27            NYC<br>  1      Jim   24  San Francisco<br>  2      Tim   22         London<br>y 2     Jane   25        Chicago<br>  3  Jessica   34    Los Angeles<br>  4     Tess   32   Philadelphia<br><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Merge_Dataframe\"><\/span>2. Merge Dataframe<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Merging dataframe is similar to SQL joins where you combine rows from multiple tables using common column values. You can do this using merge() function available in pandas library.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Based_on_one_or_more_keys\"><\/span>Based on one or more keys<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Here is the command to merge two dataframes using common column names, or keys. You need to mention the dataframes to be merged, one after the other. Then you need to mention the list of keys to be used for merging, for &#8216;on&#8217; argument.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pd.merge(df1, df2, on=[key1, key2,...]<\/pre>\n\n\n\n<p>Let us say you have the following dataframes, with the ID columns having common values<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import pandas as pd<br><br>d1 = {'Name': ['John','Jim','Tim'],<br>         'Age': [27, 24, 22],<br>         'City': ['NYC', 'San Francisco','London'],<br>         'ID':[1, 2, 3]<br>     }<br><br>d2 = {'Name': ['Jane','Jessica','Tess'],<br>         'Age': [25, 34, 32],<br>         'City': ['Chicago', 'Los Angeles','Philadelphia'],<br>         'ID':[2,3,4]<br>     }<br>     <br>df1 = pd.DataFrame(d1, index=[0, 1, 2])<br>df2 = pd.DataFrame(d2, index=[2, 3, 4])<br><\/pre>\n\n\n\n<p>Here is the code to merge the two dataframes, using ID column. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">res = pd.merge(df1,df2, on=['ID'])<br>print(res)<br><br>## output<br><br>  Name_x  Age_x         City_x  ID   Name_y  Age_y       City_y<br>0    Jim     24  San Francisco   2     Jane     25      Chicago<br>1    Tim     22         London   3  Jessica     34  Los Angeles<\/pre>\n\n\n\n<p>By default, pandas will try to do an INNER JOIN where it will pick rows with common values for ID column. If there are no common values in the key column, then the result will be an empty dataframe.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"By_specifying_type_of_merge\"><\/span>By specifying type of merge<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>You can also specify the type of join, using &#8216;how&#8217; argument. As you can see in above dataframes, the name column does not have any common values. In such cases, you can do a LEFT or RIGHT join, preserving the column values of one of the two tables. Here is an example of LEFT JOIN. The values from left dataframe are preserved whereas the corresponding values for RIGHT table are set as NaN.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">res = pd.merge(df1,df2, how='left',on=['Name'])<br>print(res)<br><br>## output<br><br>   Name  Age_x         City_x  ID_x  Age_y City_y  ID_y<br>0  John     27            NYC     1    NaN    NaN   NaN<br>1   Jim     24  San Francisco     2    NaN    NaN   NaN<br>2   Tim     22         London     3    NaN    NaN   NaN<\/pre>\n\n\n\n<p>If you want to do an outer join, then specify how=&#8217;outer&#8217;.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">res = pd.merge(df1,df2, how='outer',on=['Name'])<br>print(res)<br><br>## output<br><br>      Name  Age_x         City_x  ID_x  Age_y        City_y  ID_y<br>0     Jane    NaN            NaN   NaN   25.0       Chicago   2.0<br>1  Jessica    NaN            NaN   NaN   34.0   Los Angeles   3.0<br>2      Jim   24.0  San Francisco   2.0    NaN           NaN   NaN<br>3     John   27.0            NYC   1.0    NaN           NaN   NaN<br>4     Tess    NaN            NaN   NaN   32.0  Philadelphia   4.0<br>5      Tim   22.0         London   3.0    NaN           NaN   NaN<\/pre>\n\n\n\n<p>In all the examples above, you can see that since both tables have same column names, merge() function will automatically assign suffixes x, y, &#8230; to overlapping column names.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Join_Dataframe\"><\/span>3. Join Dataframe<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_join\"><\/span>Using join()<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Like merge, you can also use join() function to combine two dataframes. It is available in all dataframes. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">DataFrame.join(other, on=None, how='left', lsuffix='', rsuffix='', sort=False, validate=None)<\/pre>\n\n\n\n<p>Here is an example to illustrate it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import pandas as pd<br><br>d1 = {'Name': ['John','Jim','Tim'],<br>         'Age': [27, 24, 22],<br>         'ID':[1, 2, 3]<br>     }<br><br>d2 = {<br>         'City': ['NYC', 'San Francisco','London'],<br>     }<br>     <br>df1 = pd.DataFrame(d1, index=[0, 1, 2])<br>df2 = pd.DataFrame(d2, index=[2, 3, 4])<br><br>res = df1.join(df2, on='ID')<br>print(res)<br><br>## output<br><br>   Name  Age  ID           City<br>0  John   27   1            NaN<br>1   Jim   24   2            NYC<br>2   Tim   22   3  San Francisco<\/pre>\n\n\n\n<p>In the above example, the dataframe df2 is joined to df1 using index values. It works well if your dataframes do not have overlapping columns. <\/p>\n\n\n\n<p>By default, the join() function does a left join where it retains all rows and columns of left dataframe, and populates the other dataframe&#8217;s values for matching indexes. <\/p>\n\n\n\n<p>If your dataframes have overlapping columns, then you must mention the suffix to differentiate them, otherwise you will get an error.<\/p>\n\n\n\n<p>Here is an example to join the above two dataframes using ID column as merge key.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import pandas as pd<br><br>d1 = {'Name': ['John','Jim','Tim'],<br>         'Age': [27, 24, 22],<br>         'City': ['NYC', 'San Francisco','London'],<br>         'ID':[1, 2, 3]<br>     }<br><br>d2 = {'Name': ['Jane','Jessica','Tess'],<br>         'Age': [25, 34, 32],<br>         'City': ['Chicago', 'Los Angeles','Philadelphia'],<br>         'ID':[2,3,4]<br>     }<br>     <br>df1 = pd.DataFrame(d1, index=[0, 1, 2])<br>df2 = pd.DataFrame(d2, index=[2, 3, 4])<br><br>res = df1.join(df2, on='ID')<br>print(res)<br><br>## output<br>ValueError: columns overlap but no suffix specified: Index(['Name', 'Age', 'City', 'ID'], dtype='object')<\/pre>\n\n\n\n<p>Since both dataframes have overlapping columns, we get an error since we did not specify a suffix to differentiate common columns.<\/p>\n\n\n\n<p>To fix this problem, we use lsuffix argument and specify the suffix for overlapping column names.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">res = df1.join(df2, on='ID',lsuffix='_a')<br>print(res)<br><br>## output<br><br>  <strong>Name_a  Age_a         City_a  ID_a<\/strong>     Name   Age         City   ID<br>0   John     27            NYC     1      NaN   NaN          NaN  NaN<br>1    Jim     24  San Francisco     2     Jane  25.0      Chicago  2.0<br>2    Tim     22         London     3  Jessica  34.0  Los Angeles  3.0<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_how_argument\"><\/span>Using how argument<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Like merge function, you can also specify the type of join using &#8216;how&#8217; argument. Here is an example to do inner join.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">res = df1.join(df2, on='ID',lsuffix='_a', how='inner')<br>print(res)<br><br>## output<br><br>  Name_a  Age_a         City_a  ID_a     Name  Age         City  ID<br>1    Jim     24  San Francisco     2     Jane   25      Chicago   2<br>2    Tim     22         London     3  Jessica   34  Los Angeles   3<\/pre>\n\n\n\n<p>Here is an example to do left join. In this case, the values of left dataframe are retained, along with matching values from right dataframe.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">res = df1.join(df2, on='ID',lsuffix='_a', how='left')<br>print(res)<br><br>## output<br><br>  Name_a  Age_a         City_a  ID_a     Name   Age         City   ID<br>0   John     27            NYC     1      NaN   NaN          NaN  NaN<br>1    Jim     24  San Francisco     2     Jane  25.0      Chicago  2.0<br>2    Tim     22         London     3  Jessica  34.0  Los Angeles  3.0<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt several simple ways to combine data from two dataframes. Depending on your requirement, you can choose to merge, join or concatenate dataframes. concat() function allows you to combine dataframes vertically one below the other, or horizontally one beside the other. On the other hand, join() and merge() functions combine dataframes horizontally only.<\/p>\n\n\n\n<p>Also read:<br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-create-pivot-tables-in-python-pandas\/\">How to Create Pivot Tables in Python<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-connect-pandas-to-database\/\">How to Connect Pandas to Database<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/top-python-libraries-for-machine-learning\/\">Top Machine Learning Libraries in Python<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python developers may need to join or merge dataframe in Python. Here is how to merge and join Pandas dataframe.<\/p>\n","protected":false},"author":1,"featured_media":8240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301],"tags":[423],"class_list":["post-8212","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-merge-dataframe"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Merge and Join Pandas Dataframes - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Python developers may need to join or merge dataframe in Python. Here is how to merge and join Pandas dataframes.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Merge and Join Pandas Dataframes - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Python developers may need to join or merge dataframe in Python. Here is how to merge and join Pandas dataframes.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-16T07:17:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-19T06:06:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/05\/merge-join-dataframe-python.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"269\" \/>\n\t<meta property=\"og:image:height\" content=\"180\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-merge-and-join-pandas-dataframes\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-merge-and-join-pandas-dataframes\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Merge and Join Pandas Dataframes\",\"datePublished\":\"2025-05-16T07:17:30+00:00\",\"dateModified\":\"2025-05-19T06:06:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-merge-and-join-pandas-dataframes\\\/\"},\"wordCount\":868,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-merge-and-join-pandas-dataframes\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/merge-join-dataframe-python.jpg?fit=269%2C180&ssl=1\",\"keywords\":[\"merge dataframe\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-merge-and-join-pandas-dataframes\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-merge-and-join-pandas-dataframes\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-merge-and-join-pandas-dataframes\\\/\",\"name\":\"How to Merge and Join Pandas Dataframes - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-merge-and-join-pandas-dataframes\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-merge-and-join-pandas-dataframes\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/merge-join-dataframe-python.jpg?fit=269%2C180&ssl=1\",\"datePublished\":\"2025-05-16T07:17:30+00:00\",\"dateModified\":\"2025-05-19T06:06:32+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Python developers may need to join or merge dataframe in Python. Here is how to merge and join Pandas dataframes.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-merge-and-join-pandas-dataframes\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-merge-and-join-pandas-dataframes\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-merge-and-join-pandas-dataframes\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/merge-join-dataframe-python.jpg?fit=269%2C180&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/merge-join-dataframe-python.jpg?fit=269%2C180&ssl=1\",\"width\":269,\"height\":180,\"caption\":\"merge and join pandas dataframe in python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-merge-and-join-pandas-dataframes\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Merge and Join Pandas Dataframes\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sreeram-sreenivasan\\\/\"],\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/author\\\/wordpress\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Merge and Join Pandas Dataframes - Ubiq BI","description":"Python developers may need to join or merge dataframe in Python. Here is how to merge and join Pandas dataframes.","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:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/","og_locale":"en_US","og_type":"article","og_title":"How to Merge and Join Pandas Dataframes - Ubiq BI","og_description":"Python developers may need to join or merge dataframe in Python. Here is how to merge and join Pandas dataframes.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-05-16T07:17:30+00:00","article_modified_time":"2025-05-19T06:06:32+00:00","og_image":[{"width":269,"height":180,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/05\/merge-join-dataframe-python.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Merge and Join Pandas Dataframes","datePublished":"2025-05-16T07:17:30+00:00","dateModified":"2025-05-19T06:06:32+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/"},"wordCount":868,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/05\/merge-join-dataframe-python.jpg?fit=269%2C180&ssl=1","keywords":["merge dataframe"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/","name":"How to Merge and Join Pandas Dataframes - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/05\/merge-join-dataframe-python.jpg?fit=269%2C180&ssl=1","datePublished":"2025-05-16T07:17:30+00:00","dateModified":"2025-05-19T06:06:32+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Python developers may need to join or merge dataframe in Python. Here is how to merge and join Pandas dataframes.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/05\/merge-join-dataframe-python.jpg?fit=269%2C180&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/05\/merge-join-dataframe-python.jpg?fit=269%2C180&ssl=1","width":269,"height":180,"caption":"merge and join pandas dataframe in python"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-and-join-pandas-dataframes\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Merge and Join Pandas Dataframes"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/05\/merge-join-dataframe-python.jpg?fit=269%2C180&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-28s","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/8212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=8212"}],"version-history":[{"count":33,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/8212\/revisions"}],"predecessor-version":[{"id":8288,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/8212\/revisions\/8288"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/8240"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=8212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=8212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=8212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}