I have a DataFrame with 3 columns: POD (which is a code), timestamp, EAI\_ALL (number).
I want to calculate a 4th column where every row has the following value: the value of EAI\_ALL of the current row minus the value of EAI\_ALL on the previous row. This has to be done for every code (e.g. if the current code is 2 and the code in the previous row is 1, the calculated value has to be 0 because the code is different).
I managed to do this operation with the following code:

```
#group the DF by POD code
grouped = df.groupby('POD')

#Define Lambda function
eai_diff = lambda x: x.EAI_ALL - x.EAI_ALL.shift(+1)

df['EAI_Delta'] = grouped.apply(eai_diff).reset_index(0, drop=True).fillna(0)

```

This works fine, unless I have only one POD code in the DataFrame.
I keep getting this error if I apply the function to a DataFrame with only one POD code.

```
ValueError: Wrong number of items passed 48, placement implies 1

```

As you can see df has 48 rows, but with the group by it gets reduced to one row.
I need the groupby because if I have more than one POD code the operation basically has to be done for one POD code at a time.

Does anyone have any suggestion?
Thanks in advance!