Comparing values in Pandas with 'diff' and 'pct_change'

preview_player
Показать описание
Want to know how much the values in a series or data frame have changed from row to row? Meet the "diff" method, which will calculate this for you -- either from the previous row, or from any other row. And if you want to know the percentage change? Just use "pct_change" instead.
Рекомендации по теме
Комментарии
Автор

off topic Q, but inspired by a moment from this vid. When writing own functions, should I write for pd.Series or 1-column DataFrame? Sounds like could be multiple things to keep in mind when deciding

AndyWallWasWeak
Автор

What about diff by different categories? Say I have corn, rice, beans and wheat prices in the same df, and I want to compare the price changes within the same catogories.

tyl