title: How do I check if pandas df column value exists based on value in another column?
body: <p>I have a pandas dataframe as below</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: center;">Year</th>
  <th style="text-align: center;">ID</th>
  <th style="text-align: center;">Value</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: center;">2016</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">100</td>
  </tr>
  <tr>
  <td style="text-align: center;">2017</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">102</td>
  </tr>
  <tr>
  <td style="text-align: center;">2017</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">105</td>
  </tr>
  <tr>
  <td style="text-align: center;">2018</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">98</td>
  </tr>
  <tr>
  <td style="text-align: center;">2016</td>
  <td style="text-align: center;">2</td>
  <td style="text-align: center;">121</td>
  </tr>
  <tr>
  <td style="text-align: center;">2016</td>
  <td style="text-align: center;">2</td>
  <td style="text-align: center;">101</td>
  </tr>
  <tr>
  <td style="text-align: center;">2016</td>
  <td style="text-align: center;">2</td>
  <td style="text-align: center;">133</td>
  </tr>
  <tr>
  <td style="text-align: center;">2018</td>
  <td style="text-align: center;">3</td>
  <td style="text-align: center;">102</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I want to check if the ID only exists for the year 2018 only. My desired output is as below:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: center;">Year</th>
  <th style="text-align: center;">ID</th>
  <th style="text-align: center;">Value</th>
  <th style="text-align: center;">ID_only_in_2018</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: center;">2016</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">100</td>
  <td style="text-align: center;">0</td>
  </tr>
  <tr>
  <td style="text-align: center;">2017</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">102</td>
  <td style="text-align: center;">0</td>
  </tr>
  <tr>
  <td style="text-align: center;">2017</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">105</td>
  <td style="text-align: center;">0</td>
  </tr>
  <tr>
  <td style="text-align: center;">2018</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">98</td>
  <td style="text-align: center;">0</td>
  </tr>
  <tr>
  <td style="text-align: center;">2016</td>
  <td style="text-align: center;">2</td>
  <td style="text-align: center;">121</td>
  <td style="text-align: center;">0</td>
  </tr>
  <tr>
  <td style="text-align: center;">2016</td>
  <td style="text-align: center;">2</td>
  <td style="text-align: center;">101</td>
  <td style="text-align: center;">0</td>
  </tr>
  <tr>
  <td style="text-align: center;">2016</td>
  <td style="text-align: center;">2</td>
  <td style="text-align: center;">133</td>
  <td style="text-align: center;">0</td>
  </tr>
  <tr>
  <td style="text-align: center;">2018</td>
  <td style="text-align: center;">3</td>
  <td style="text-align: center;">102</td>
  <td style="text-align: center;">1</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Please, how can I achieve this in python?</p>