In my dataframe I will end up with a column that only has few non-nan values. I want to use the non-nan values as grouping variables for all preceding rows that do contain a NaN value. To simulate it, I made the following array:

```
count = np.array([np.NaN,np.NaN,np.NaN,3,np.NaN,np.NaN,6,np.NaN,np.NaN,np.NaN,np.NaN,np.NaN,12])
count = Series(count)

```

For this array I was able to create a filling function

```
def pad_expsamp_time(array):
    sect = np.zeros(array.size) # create array filled with zeros
    inds = array.index[array.notnull()] # select the non-zero values
    rev_inds = inds[::-1] # sort high to low
    # fill array with value until index of value. Repeat for lower values. 
    for i in rev_inds: 
        sect[:i] = i
    return Series(sect)

```

This function works, when it can assume that the indices of the non-nan values is equal to the actual values. However, **how can I fill an array when the indices are not equal to the content?** 

---

For example, what if array count is:

```
count = np.array([np.NaN,np.NaN,np.NaN,1,np.NaN,np.NaN,2,np.NaN,np.NaN,np.NaN,np.NaN,np.NaN,3])

```

And the desired output is

```
count = np.array([1,1,1,1,2,2,2,3,3,3,3,3,3]

```

It is possible that there are NaNs at the end of the array. I would like these to stay NaNs, so that the dataframe will ignore them. 

```
count = np.array([np.NaN,np.NaN,np.NaN,1,np.NaN,np.NaN,2,np.NaN,np.NaN,3,np.NaN,np.NaN]) 
# Will become:
count = np.array([1,1,1,1,2,2,2,3,3,3,np.nan,np.nan]

```