title: How to fill missing values in a dataset with multiple timepoints but i only want to carry the last observation forward for each participant?
body: <p>I have a python data frame with health data and participants appearing at timepoints 1, 2, and 3. I have a column called 'BPMEDS' with missing data, and a lot of it is the last time point that is missing (whether that is 1, 2, or 3). The last filled row for BP MEDS is above each empty row.
  So 'randid' 16799 does not have 'bpmeds' for period 3, but does for period 2. I simply want to copy the value from the last available period. Each participant has an ID, so the ID can appear up to 3 times in the dataset.</p>
  <pre><code> RANDID  BPMEDS  PERIOD
  26   16799     0.0       1
  27   16799     0.0       2
  28   16799     NaN       3
  29   19304     0.0       1
  30   20375     0.0       1
  31   20375     0.0       2
  32   23727     1.0       1
  </code></pre>
  <p>If theres only period 1 available with an empty 'bpmeds' field then i will have to ignore this and come to it later.</p>
  <p>I want to fill in the missing rows with the last observation available for each participant.</p>
  <p>I'm not sure where, to begin with this.</p>
  <pre><code>for ind in df.index:
      if df['PERIOD'][ind] != '1':
         df['BPMEDS'][ind] = df.groupby(['RANDID']).fillna(method='ffill')
  </code></pre>
  <p>That is what I have tried and i get a value error and type error.</p>