title: Select nearest date first day of month in a python dataframe
body: <p>i have this kind of dataframe<br />
  <a href="https://i.stack.imgur.com/0J8pP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0J8pP.png" alt="enter image description here" /></a></p>
  <p>These data represents the value of an consumption index generally encoded once a month (at the end or at the beginning of the following month) but sometimes more. This value can be resetted to &quot;0&quot; if the counter is out and be replaced. Moreover some month no data is available.</p>
  <p>I would like select only one entry per month but this entry has to be the nearest to the first day of the month AND inferior to the 15th day of the month (because if the day is higher it could be the measure of the end of the month). Another condition is that if the difference between two values is negative (the counter has been replaced), the value need to be kept even if the date is not the nearest day near the first day of month.</p>
  <p>For example, the output data need to be<br />
  <a href="https://i.stack.imgur.com/z66Ql.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/z66Ql.png" alt="enter image description here" /></a></p>
  <p>The purpose is to calculate only a consumption per month.</p>
  <p>A solution is to parse the dataframe (as a array) and perform some if conditions statements. However i wonder if there is &quot;simple&quot; alternative to achieve that.</p>
  <p>Thank you</p>