Good Morning,
I have the following dataframe:
print(df)
a b
1 6
1 4
4 5
4 2
...
And I would like to get:
print(final_df)
a b c
1 6 2
1 4 2
4 5 3
4 2 3
...
I tried using:
df["c"] = df.groupby("a")["b"].transform(np.diff)
And it works of a small test set with two rows, but whenever I try to run in on the whole dataset, it returns:
ValueError: Wrong number of items passed 0, placement implies 1
How can I create final_df ?