Question: With a DataFrame having `ref` and `value` as columns:

```
    ref  value  buffer
0     0      0       0
1     1      3       0
2     2      4       0
3     0      2       2
4     8     21       2
5     0     -2      -2
6     3     13      -2
7     6     17      -2
8     2      4      -2
9     0      5       5
10    0      5       5

```

How would you create the third `buffer` column which respects this definition:

* if `ref == 0` then buffer = value
* if `ref != 0` then buffer = value of the closest previous row where `ref = 0`

Answer: 
Use `where` to keep `df.value` when `df.ref == 0`. The rest will be `np.nan`. Use `ffill` to fill `np.nan` from previous rows. Use assign to create new column. 

Note that I did not cast the column as int. I left it out because it is possible the the first several rows of ref are non zero. If this were to happen, the initial rows of buffer would be `np.nan` with nothing to forward fill from. In this situation, I could not cast to int. 

```
df.assign(buffer=df.value.where(df.ref.eq(0)).ffill())

```
You could the condition in Pandas

```
df.ix[condition, column_to_apply] = value

```