Filling a pandas dataframe column with data between two indexes

  dataframe, pandas, python

I have a dataframe:

event job_id_num
JOB_START 12345
JOB_END 12345
RETOOL 99999
JOB_START 12346
JOB_END 12346

Between the JOB_START and JOB_END events there can be x number of rows depending on what job steps take place for a given job. The JOB_START and END events are marked with the job_id_number, but the rows between are not. I need to fill the rows in between the existing job_id_nums.

I started with this solution, but this solution is for a multi-index dataframe, whereas mine is not. I can ffill() the values in I need, but I have to know how many rows I need to fill in as the number of rows to be filled will change job_id_num to job_id_num.

Source: Python Questions

LEAVE A COMMENT