{
    "componentChunkName": "component---src-templates-blog-post-js",
    "path": "/join-pandas-dataframes-with-the-join-method/",
    "result": {"data":{"markdownRemark":{"html":"<p>I have an Excel workbook named <del>budget.xlsx</del>, which has two worksheets: <del>sheet1</del> &#x26; <del>sheet2</del>.</p>\n<p>Let’s read both the worksheets into DataFrames:</p>\n<pre class=\"grvsc-container synthwave-84\" data-language=\"py\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"grvsc-gutter-pad\"></span><span class=\"grvsc-gutter grvsc-line-number\" aria-hidden=\"true\" data-content=\"1\"></span><span class=\"grvsc-source\"><span class=\"mtk10\">import</span><span class=\"mtk15\"> pandas </span><span class=\"mtk10\">as</span><span class=\"mtk15\"> pd</span></span></span>\n<span class=\"grvsc-line\"><span class=\"grvsc-gutter-pad\"></span><span class=\"grvsc-gutter grvsc-line-number\" aria-hidden=\"true\" data-content=\"2\"></span><span class=\"grvsc-source\"></span></span>\n<span class=\"grvsc-line\"><span class=\"grvsc-gutter-pad\"></span><span class=\"grvsc-gutter grvsc-line-number\" aria-hidden=\"true\" data-content=\"3\"></span><span class=\"grvsc-source\"><span class=\"mtk15\">budget1 </span><span class=\"mtk12\">=</span><span class=\"mtk15\"> pd.</span><span class=\"mtk6\">read_excel</span><span class=\"mtk15\">(</span><span class=\"mtk16\">&quot;budget.xlsx&quot;</span><span class=\"mtk15\">, </span><span class=\"mtk8 mtki\">sheet_name</span><span class=\"mtk12\">=</span><span class=\"mtk16\">&quot;sheet2&quot;</span><span class=\"mtk15\">).</span><span class=\"mtk6\">drop_duplicates</span><span class=\"mtk15\">()</span></span></span>\n<span class=\"grvsc-line\"><span class=\"grvsc-gutter-pad\"></span><span class=\"grvsc-gutter grvsc-line-number\" aria-hidden=\"true\" data-content=\"4\"></span><span class=\"grvsc-source\"></span></span>\n<span class=\"grvsc-line\"><span class=\"grvsc-gutter-pad\"></span><span class=\"grvsc-gutter grvsc-line-number\" aria-hidden=\"true\" data-content=\"5\"></span><span class=\"grvsc-source\"><span class=\"mtk15\">budget1</span></span></span></code></pre>\n<p><strong>Output:</strong></p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 432px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/b95d744c2a386fe4b279ebf9382e9899/dc3b1/budget1.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 78.99999999999999%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAIAAACZeshMAAAACXBIWXMAAA7DAAAOwwHHb6hkAAACSUlEQVQoz1VT6ZKkIBib93+/7e5ptVVEORVBOeTc1amZnc4PCqoSkgofH1GtnpO4bynllFLO55quQ0wpxphSCiGkGEvOKedz/037yMEna7I/Us7O6s9n1XV9Vdfeh1LKOEKMJkJZXdcTQk1VPZ/V7X6rqibn/FG+oaSEEHLOAejv9ztG6HG/fz4eTdve/tzut9uEJkoZ4+z2eNwfjxjjf3EMYdv3UooQAsIxpsQ5bbteSOms5Yxpo3MuKSXKGCE4pV/OIQSlVM6ZM96DIYQwc9682nkR1hhGya73GGMIgVCK0bv4vJ7Ph3OU0a4H6yqauu7aFhPa9/3QA6mkMdZaizGGcDgL+xGnFK21pRSjNaH0cEfXtQBCrU0pRa7COvvFXITABOdS3pwZ485ZhFBV1caYYRg+n0/Kl9MNoUUs5gIlpOvaN+fgvdq2UsoqxDCcqay1PejEKnPOYp6NNV/PiwkZxynnX86Hc+sq01ky73vgvd82NY5QSpVymjlTmwoheO/5zBGa3pztVZj3nmDSNK9NbWDoX23D50UphaZplatzzlrHZw7hEOMvcT5zulLKpuSyCqUUAKDt+vVUIoLxcbgv5jwvmNC3wozWlDLnHCW4bl7WOqP357MilB/OYTRdhdl93wc4TON77BjDrvU1YQub+XE4NE3TOMpr7KQQxpgvphACY/Iz2/lKqyilKSVGaQ+AMRoA8GoaSjlCGIJh25S/MED4atu3j2GNWaX03st1ZezML1bBOVNSMcY457vW7sK8LPM8/xP/BVhni7HBzJMkAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Budget\"\n        title=\"Budget\"\n        src=\"/static/b95d744c2a386fe4b279ebf9382e9899/dc3b1/budget1.png\"\n        srcset=\"/static/b95d744c2a386fe4b279ebf9382e9899/56d15/budget1.png 200w,\n/static/b95d744c2a386fe4b279ebf9382e9899/d9f49/budget1.png 400w,\n/static/b95d744c2a386fe4b279ebf9382e9899/dc3b1/budget1.png 432w\"\n        sizes=\"(max-width: 432px) 100vw, 432px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<pre class=\"grvsc-container synthwave-84\" data-language=\"py\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"grvsc-gutter-pad\"></span><span class=\"grvsc-gutter grvsc-line-number\" aria-hidden=\"true\" data-content=\"1\"></span><span class=\"grvsc-source\"><span class=\"mtk15\">budget2 </span><span class=\"mtk12\">=</span><span class=\"mtk15\"> pd.</span><span class=\"mtk6\">read_excel</span><span class=\"mtk15\">(</span><span class=\"mtk16\">&quot;budget.xlsx&quot;</span><span class=\"mtk15\">, </span><span class=\"mtk8 mtki\">sheet_name</span><span class=\"mtk12\">=</span><span class=\"mtk16\">&quot;sheet1&quot;</span><span class=\"mtk15\">).</span><span class=\"mtk6\">drop_duplicates</span><span class=\"mtk15\">()</span></span></span>\n<span class=\"grvsc-line\"><span class=\"grvsc-gutter-pad\"></span><span class=\"grvsc-gutter grvsc-line-number\" aria-hidden=\"true\" data-content=\"2\"></span><span class=\"grvsc-source\"></span></span>\n<span class=\"grvsc-line\"><span class=\"grvsc-gutter-pad\"></span><span class=\"grvsc-gutter grvsc-line-number\" aria-hidden=\"true\" data-content=\"3\"></span><span class=\"grvsc-source\"><span class=\"mtk15\">budget2</span></span></span></code></pre>\n<p><strong>Output:</strong></p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 325px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/301fd948188af7113cac0c17ce4d5818/e5cc6/budget2.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 106%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAVCAIAAADJt1n/AAAACXBIWXMAAA7DAAAOwwHHb6hkAAACZElEQVQ4y22U65KiMBCF5/2fbnVE8AYJJFEQFUi6Qy7AFqHGmpX9fgWo5pw+3fAFIpfFGQTXTWOtM31vjB2HwRjjnLPWeu+NMcZa59w4BLy3ga9pGEZnRz8/GMdxmqbL6biLYkLoPombV3NIkvPpdIjjbRTto10URdvNtzFmmqav6RePx4NSer1eGWNpmka7iHPOGOOcCyE4F1mWJkmy2W7btv0s7rq2KAqlABGyLPve7pqmAQAZQMSyvJ6Oh10UKYDPYu8sah2OY32vaMF0388XoZ1pmgbvqqrMCLHWfRY7a6VUPkRSVWWaEUQMV4FhML0uyxvN897Yz2LZtZwLAACEPM/3Ufx8PgFABQDg+Xwkh/2fzUYBrpSd7aQMqQ+zMqGIOI1jUJ3vmr6v6yoj1NiVsvdOKZg7HMembQrG3z0vOOe69sWYsG7Vs5Id51cVbFdVeTxflrTfttvXk9B8G+0AV7aN6bu2c25OJ8w8BwDvvQt477XGqioZY26t7J2VUi7nuq4vl0yHyb1H5awVgmU0c86vbCtVlpUOFEWREaKURNS4oLWSXUZItI9R95/FCHC/1yZwu90Y5wBgjOkDxhgZVvB0vvS9Wdt2y8bPe14/CsYR/7GNqMpSxIfDf0YVlO866FRVxTgDUFr3+gcEJYQ4X1K9tg1Klrfyp2dG6GfPUnY5JafzWa9tO2fbrnunTWm+KATbs3MFHWP0eDr+d0nkva6Xv8S9qvKiAABr7RKhtRZAXYXICDG/P4wlkkddpymZe0MsimK/T15Ng4gQQMTX60lJFicJrjds/HnRO95xxW+xv8SisuUJJ265AAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Budget\"\n        title=\"Budget\"\n        src=\"/static/301fd948188af7113cac0c17ce4d5818/e5cc6/budget2.png\"\n        srcset=\"/static/301fd948188af7113cac0c17ce4d5818/56d15/budget2.png 200w,\n/static/301fd948188af7113cac0c17ce4d5818/e5cc6/budget2.png 325w\"\n        sizes=\"(max-width: 325px) 100vw, 325px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<p>Note that both the DataFrames have the <del>Store Code</del> column in common.</p>\n<p>Our goal is to join the <del>July’19 Achievement</del> column from the <del>budget2</del> DataFrame to the <del>budget 1</del> DataFrame.</p>\n<p>We can do so using the <del>join()</del> method.</p>\n<p>The <del>Store Code</del> column, <em>present in both the DataFrames</em>, will act as the key for the joining operation.</p>\n<pre class=\"grvsc-container synthwave-84\" data-language=\"py\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"grvsc-gutter-pad\"></span><span class=\"grvsc-gutter grvsc-line-number\" aria-hidden=\"true\" data-content=\"1\"></span><span class=\"grvsc-source\"><span class=\"mtk15\">budget1.</span><span class=\"mtk6\">set_index</span><span class=\"mtk15\">(</span><span class=\"mtk8 mtki\">keys</span><span class=\"mtk12\">=</span><span class=\"mtk16\">&quot;Store Code&quot;</span><span class=\"mtk15\">).</span><span class=\"mtk6\">join</span><span class=\"mtk15\">(budget2.</span><span class=\"mtk6\">set_index</span><span class=\"mtk15\">(</span><span class=\"mtk8 mtki\">keys</span><span class=\"mtk12\">=</span><span class=\"mtk16\">&quot;Store Code&quot;</span><span class=\"mtk15\">)).</span><span class=\"mtk6\">reset_index</span><span class=\"mtk15\">()</span></span></span></code></pre>\n<h6 id=\"learn-how-to-convert-a-column-into-an-index-in-my-blog-post-here\" style=\"position:relative;\"><a href=\"#learn-how-to-convert-a-column-into-an-index-in-my-blog-post-here\" aria-label=\"learn how to convert a column into an index in my blog post here permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Learn how to convert a column into an index in my blog post <a href=\"https://hemanta.io/pandas-set-index-andreset-index-methods/\">here</a>.</h6>\n<p><strong>Output:</strong></p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 546px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/0371b9c1e658967dd0b693ce9f972587/8c78b/combinedDataFrames.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 62%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAIAAADtbgqsAAAACXBIWXMAAA7DAAAOwwHHb6hkAAABxUlEQVQoz1WR2XLbMAxF8/+/l3GSSTM1JYogJa6iuAkkpY5jN27xjDsH5+IFvdutPnpH3JVU1tpaaz+69z5swTm7rqvWepkX59zqnJRSSam1jjG+nN9TShFCEELe398ZAB2Hz89fX19fb5fLSOk0TZfL28fHBwNGvuf19RWAP8L7vqeUjt458JgSMKAMckpGyYJ4nqexRkp5X+63NXBufYZDCCmlYRi898DYSKnRmjO2xYiIUkrO+b7vpZSc80Sp1uYRRsSYYmtVzMJYS8gVOI8hKLmkXHrv1loh5tZarbW1NnPunHuSN7+VksdxXFc/DAOhFBGtVn4LiKi1ZsDu5H3f6Y2s/3XOiDhNUyklxghC1FpXa1Iu53korYWYe++ttd47paMx9tm29z7nPJBhC2GZBWMTIhol72RzO1v8kAkhT+daaynlXoy19vf1CkIoKQGg7Hgcx7qu87L8kDljzv51zjmvqy85UzptWzDaEDKklNQy+3AjL8si+IOcUx4IkUr992dEnOd52zbOJuCitXZ3Po7DOSfmh3NrDQCstS/HcZznGWPU2pSSKaVbCAATAHDO6TiG7z+LZZ7Yo+2U0vV6VUr/AWctpcmFU4H8AAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Combined DataFrames\"\n        title=\"Combined DataFrames\"\n        src=\"/static/0371b9c1e658967dd0b693ce9f972587/8c78b/combinedDataFrames.png\"\n        srcset=\"/static/0371b9c1e658967dd0b693ce9f972587/56d15/combinedDataFrames.png 200w,\n/static/0371b9c1e658967dd0b693ce9f972587/d9f49/combinedDataFrames.png 400w,\n/static/0371b9c1e658967dd0b693ce9f972587/8c78b/combinedDataFrames.png 546w\"\n        sizes=\"(max-width: 546px) 100vw, 546px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    position: relative;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n    line-height: 1.4;\n  }\n  \n  .grvsc-code {\n    display: table;\n  }\n  \n  .grvsc-line {\n    display: table-row;\n    box-sizing: border-box;\n    width: 100%;\n    position: relative;\n  }\n  \n  .grvsc-line > * {\n    position: relative;\n  }\n  \n  .grvsc-gutter-pad {\n    display: table-cell;\n    padding-left: 0.75rem;\n    padding-left: calc(var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem)) / 2);\n  }\n  \n  .grvsc-gutter {\n    display: table-cell;\n    -webkit-user-select: none;\n    -moz-user-select: none;\n    user-select: none;\n  }\n  \n  .grvsc-gutter::before {\n    content: attr(data-content);\n  }\n  \n  .grvsc-source {\n    display: table-cell;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-source:empty::after {\n    content: ' ';\n    -webkit-user-select: none;\n    -moz-user-select: none;\n    user-select: none;\n  }\n  \n  .grvsc-gutter + .grvsc-source {\n    padding-left: 0.75rem;\n    padding-left: calc(var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem)) / 2);\n  }\n  \n  /* Line transformer styles */\n  \n  .grvsc-has-line-highlighting > .grvsc-code > .grvsc-line::before {\n    content: ' ';\n    position: absolute;\n    width: 100%;\n  }\n  \n  .grvsc-line-diff-add::before {\n    background-color: var(--grvsc-line-diff-add-background-color, rgba(0, 255, 60, 0.2));\n  }\n  \n  .grvsc-line-diff-del::before {\n    background-color: var(--grvsc-line-diff-del-background-color, rgba(255, 0, 20, 0.2));\n  }\n  \n  .grvsc-line-number {\n    padding: 0 2px;\n    text-align: right;\n    opacity: 0.7;\n  }\n  \n  .synthwave-84 { background-color: #262335; }\n  .synthwave-84 .mtki { font-style: italic; }\n  .synthwave-84 .mtk10 { color: #FEDE5D; }\n  .synthwave-84 .mtk15 { color: #FF7EDBFF; }\n  .synthwave-84 .mtk12 { color: #FFFFFFEE; }\n  .synthwave-84 .mtk6 { color: #36F9F6; }\n  .synthwave-84 .mtk16 { color: #FF8B39; }\n  .synthwave-84 .mtk8 { color: #72F1B8; }\n  .synthwave-84 .grvsc-line-highlighted::before {\n    background-color: var(--grvsc-line-highlighted-background-color, rgba(255, 255, 255, 0.1));\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, rgba(255, 255, 255, 0.5));\n  }\n</style>","frontmatter":{"title":"Join Pandas DataFrames With The join() Method","date":"2021-08-11"}}},"pageContext":{"slug":"/join-pandas-dataframes-with-the-join-method/","prev":{"fields":{"slug":"/pandas-groupby-method/"},"frontmatter":{"modules":null}},"next":{"fields":{"slug":"/copy-a-range-using-excel-vba/"},"frontmatter":{"modules":null}}}},
    "staticQueryHashes": ["3159585216"]}