Question: Suppose we have a DataFrame like this, only with many, many more index A values:

```
df = pd.DataFrame([[1,2,1,2],
              [1,1,2,2],
              [2,2,1,0],
              [1,2,1,2],
              [2,1,1,2]    ], columns=['A','B','c1','c2'])
df.groupby(['A','B']).sum()

## result
     c1  c2
A B        
1 1   2   2
  2   2   4
2 1   1   2
  2   1   0

```

How can I get a data frame that consists of the difference between rows, by the second level of the index, level B?
The output here would be

```
A    c1  c2
1     0  -2
2     0   2

```

**Note** In my particular use case, I have a lot of column A values, so I can write out the value for A explicitly.

Answer: 
I have to write this as an answer, but it is not 100% an answer to your code, these are just tips for you to have better code. (So if anyone sees this too, they are aware too)

First of all, avoid 100% writing code in other language than English, as we are following it (we do not speak your language) and we do not understand nearly anything unless we use a Translator...

So, if you are going to use Laravel, try to avoid using `DB`, when you can just use the Model (hopefully you have created it...).

So your class should look like this:

```php
public function lastNumber()
{
    return NomorNpe::orderByDesc('id')->first();
}

```

Then your controller should be like:

```php
public function store(Request $request, NomorNpe $nomor_npe)
{
    NomorNpe::create([
        'nomor_npe' => $nomor_npe->lastNumber() ? $nomor_npe->lastNumber()->nomor_npe + 1 : 1,
        'tanggal_npe' => $request->input('tanggal_npe')
    ]);

    return redirect('nomor_npe')->with('success', 'Nomor NPE berhasil ditambahkan');
}

```

See how I reduced everything from 13 lines of code to 5 lines of code and is 100% readable... (Or 9 lines to 2)

---

Make sure to use what Laravel brings you as "default" for it, use Models not `DB::table('xxx')`, take advantage of Eloquent.
Use this code for starting the number from 1, when the year changed:

```
public function nomor_npe_store(Request $req) {
    $tanggal_npe = $req->input('tanggal_npe');
    //---Current Date
    $date = date('Y-m-d', time());

    //---NOMOR NPE
    $nomor_npe = DB('number_npe')->whereYear('tanggal_npe', $date)->max('normor_npe');
    if (!$nomor_npe) {
        $nomor_npe = 1;
    } else {
        $nomor_npe++;
    }
    DB::table('nomor_npe')->insert([
        'nomor_npe'    => $nomor_npe,
        'tanggal_npe'    => $tanggal_npe
    ]);

    return redirect('nomor_npe')->with('success','Nomor NPE berhasil ditambahkan');
}

```