DataFrame.diff and DataFrame.shift: Take the Difference between Rows within a Column in Pandas

DataFrame.diff and DataFrame.shift: Take the Difference between Rows within a Column in Pandas

If you want to get the difference between rows within a column, use DataFrame.diff().

This will leave the first index null. You can shift the rows up to match the first difference with the first index using DataFrame.shift(-1).

Find an example above.

#datascience #python

Search

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran