title: Bring max value from a table based on the values of another table with PySpark
body: <p>I have two Spark DataFrames, the first one (<code>Events</code>) contains events information as following:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Event_id</th>
  <th>Date</th>
  <th>User_id</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>2019-04-19</td>
  <td>1</td>
  </tr>
  <tr>
  <td>2</td>
  <td>2019-05-30</td>
  <td>2</td>
  </tr>
  <tr>
  <td>3</td>
  <td>2020-01-20</td>
  <td>1</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>The second one (<code>User</code>) contains information from users as below:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Id</th>
  <th>User_id</th>
  <th>Date</th>
  <th>Weight-kg</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>1</td>
  <td>2019-04-05</td>
  <td>78</td>
  </tr>
  <tr>
  <td>2</td>
  <td>1</td>
  <td>2019-04-17</td>
  <td>75</td>
  </tr>
  <tr>
  <td>3</td>
  <td>2</td>
  <td>2019-10-10</td>
  <td>50</td>
  </tr>
  <tr>
  <td>4</td>
  <td>1</td>
  <td>2020-02-10</td>
  <td>76</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>What I wonder to know is how to bring the latest value of weight from <code>User</code> before the <code>Event Date</code> using PySpark?</p>
  <p>The return of this code must be the following table:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Event_id</th>
  <th>Date</th>
  <th>User_id</th>
  <th>Weight-kg</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>2019-04-19</td>
  <td>1</td>
  <td>75</td>
  </tr>
  <tr>
  <td>2</td>
  <td>2019-05-30</td>
  <td>2</td>
  <td>null</td>
  </tr>
  <tr>
  <td>3</td>
  <td>2020-01-20</td>
  <td>1</td>
  <td>75</td>
  </tr>
  </tbody>
  </table>
  </div>