Following the example I used in Python, where I want to conditionally join two dataframes with 'wildcard' categories, I'll demonstrate the same technique in Julia and the DataFramesMeta package.

In [1]:
using DataFramesMeta
In [92]:
# Create our two dataframes, starting with the left dataframe
sales_volume_table = DataFrame("date"=>["2021-11-15", "2021-11-20", "2021-11-25", "2021-11-26"], 
                               "quantity"=>[1,2,3,2],
                               "brand"=>["Outdoor", "Leisure", "Athletic", "Outdoor"])
Out[92]:

4 rows × 3 columns

datequantitybrand
StringInt64String
12021-11-151Outdoor
22021-11-202Leisure
32021-11-253Athletic
42021-11-262Outdoor
In [93]:
# right dataframe
promos_table = DataFrame("start_date"=>["2021-11-01", "2021-11-25"],
                         "end_date"=>["2021-11-25", "2021-11-26"],
                         "brand"=>["ANY", "Outdoor"],
                         "rebate_per_unit"=>[3,5])
Out[93]:

2 rows × 4 columns

start_dateend_datebrandrebate_per_unit
StringStringStringInt64
12021-11-012021-11-25ANY3
22021-11-252021-11-26Outdoor5

Now we want to left join both dataframes where there is either a brand match or brand is 'ANY'. Julia has a crossjoin function that does exactly what we're looking for without the need to create an intermediate column like we did in pandas.

In [99]:
results = crossjoin(sales_volume_table, promos_table, makeunique=true)
Out[99]:

8 rows × 7 columns

datequantitybrandstart_dateend_datebrand_1rebate_per_unit
StringInt64StringStringStringStringInt64
12021-11-151Outdoor2021-11-012021-11-25ANY3
22021-11-151Outdoor2021-11-252021-11-26Outdoor5
32021-11-202Leisure2021-11-012021-11-25ANY3
42021-11-202Leisure2021-11-252021-11-26Outdoor5
52021-11-253Athletic2021-11-012021-11-25ANY3
62021-11-253Athletic2021-11-252021-11-26Outdoor5
72021-11-262Outdoor2021-11-012021-11-25ANY3
82021-11-262Outdoor2021-11-252021-11-26Outdoor5
In [100]:
# Filter the results where the two columns match, OR the right column is 'ANY'
@rsubset(results, (:brand==:brand_1) || (:brand_1=="ANY"), 
                  (:date>=:start_date) && (:date <=:end_date))
Out[100]:

4 rows × 7 columns

datequantitybrandstart_dateend_datebrand_1rebate_per_unit
StringInt64StringStringStringStringInt64
12021-11-151Outdoor2021-11-012021-11-25ANY3
22021-11-202Leisure2021-11-012021-11-25ANY3
32021-11-253Athletic2021-11-012021-11-25ANY3
42021-11-262Outdoor2021-11-252021-11-26Outdoor5
In [ ]: