# Cross join DataFrames

**URL:** <https://discourse.julialang.org/t/cross-join-dataframes/76787>\
**Category:** General Usage\
**Tags:** dataframes\
**Created:** [February 20, 2022, 8:47am UTC](https://discourse.julialang.org/t/cross-join-dataframes/76787 "2022-02-20T08:47:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mastomaki](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@Mastomaki](https://discourse.julialang.org/u/Mastomaki)\
**Post date:** [February 20, 2022, 8:47am UTC](https://discourse.julialang.org/t/cross-join-dataframes/76787/1 "2022-02-20T08:47:52Z")

</div>

How can I cross join two dataframes A and B? In other words, combine every row in A with every row in B? I prefer not to do tricks like adding temporary columns.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [February 20, 2022, 9:13am UTC](https://discourse.julialang.org/t/cross-join-dataframes/76787/2 "2022-02-20T09:13:40Z")

</div>

use `crossjoin`:

```julia
  julia> df1 = DataFrame(X=1:3)
  3×1 DataFrame
   Row │ X
       │ Int64
  ─────┼───────
     1 │ 1
     2 │ 2
     3 │ 3

  julia> df2 = DataFrame(Y=["a", "b"])
  2×1 DataFrame
   Row │ Y
       │ String
  ─────┼────────
     1 │ a
     2 │ b

  julia> crossjoin(df1, df2)
  6×2 DataFrame
   Row │ X Y
       │ Int64 String
  ─────┼───────────────
     1 │ 1 a
     2 │ 1 b
     3 │ 2 a
     4 │ 2 b
     5 │ 3 a
     6 │ 3 b

```
