Say I have a dataframe with 3 columns: Date, Ticker, Value (no index, at least to start with). I have many dates and many tickers, but each (ticker, date)
tupl
I know this is an old question, so I'm assuming this functionality didn't exist at the time. But for those with this question now, this solution works well:
df.sort_values(['ticker', 'date'], inplace=True)
df['diffs'] = df.groupby('ticker')['value'].diff()
In order to return to the original order, you can the use
df.sort_index(inplace=True)