I have a dataframe that looks as follows:

```
idx  prev_val  val  type
 0      nan     8    a
 1      nan     9    a
 2      nan     7    a
 0      nan     3    b
 1      nan     1    b
 0      nan     2    c
 1      nan     7    c
 2      nan     5    c
 3      nan     4    c

```

I want that, per type, for each row that idx > 0, the value of `prev_val` will be taken from `val` of the previous row. So, the new dataframe will be:

```
idx  prev_val  val  type
 0      nan     8    a
 1       8      9    a
 2       9      7    a
 0      nan     3    b
 1       3      1    b
 0      nan     2    c
 1       2      7    c
 2       7      5    c
 3       5      4    c

```

What is the best way to do this?