title: Is it possible to reference a different dataframe when using Polars expression without using Lambda?
body: <p>Is there a way to reference another Polars Dataframe in Polars expressions without using lambdas?</p>
  <p>Just to use a simple example - suppose I have two dataframes:</p>
  <pre class="lang-py prettyprint-override"><code>df_1 = pl.DataFrame(
      {
          &quot;time&quot;: pl.date_range(
              low=date(2021, 1, 1),
              high=date(2022, 1, 1),
              interval=&quot;1d&quot;,
          ),
          &quot;x&quot;: pl.arange(0, 366, eager=True),
      }
  )
  
  df_2 = pl.DataFrame(
      {
          &quot;time&quot;: pl.date_range(
              low=date(2021, 1, 1),
              high=date(2021, 2, 1),
              interval=&quot;1mo&quot;,
          ),
          &quot;y&quot;: [50, 100],
      }
  )
  </code></pre>
  <p>For each <em>y</em> value in <strong>df_2</strong>, I would like to find the maximum date in <strong>df_1</strong>, conditional on the <em>x</em> value being lower than the <em>y</em>.</p>
  <p>I am able to perform this using apply/lambda (see below), but just wondering whether there is a more idiomatic way of performing this operation?</p>
  <pre class="lang-py prettyprint-override"><code>df_2.groupby(&quot;y&quot;).agg(
      pl.col(&quot;y&quot;).apply(lambda s: df_1.filter(pl.col(&quot;x&quot;) &lt; s).select(pl.col(&quot;time&quot;)).max()[0,0]).alias('latest')
  )
  </code></pre>
  <p>Edit:</p>
  <p>Is it possible to pre-filter <code>df_1</code> prior to using <code>join_asof</code>. So switching the question to look for the min instead of the max, on an individual case this is what I would do:</p>
  <pre class="lang-py prettyprint-override"><code>   (
      df_2
      .filter(pl.col('y') == 50)
      .join_asof(
                  df_1
                  .sort(&quot;x&quot;)
                  .filter(pl.col('time') &gt; date(2021,11,1))
                  .select([
                      pl.col(&quot;time&quot;).cummin().alias(&quot;time_min&quot;),
                      pl.col(&quot;x&quot;).alias(&quot;original_x&quot;),
                      (pl.col(&quot;x&quot;) + 1).alias(&quot;x&quot;),
                  ]),
              left_on=&quot;y&quot;,
              right_on=&quot;x&quot;,
              strategy=&quot;forward&quot;,
      )
  )
  </code></pre>
  <p>Is there a way to generalise this merge without using a loop / apply function?</p>