Assuming you have a pandas DataFrame and you want to subtract one row from another, you can use the .diff()
method with a specified number of periods. Here's an example:
main.py186 chars12 lines
This will output:
main.py44 chars4 lines
The diff()
method calculates the difference between each row and the row preceding it. We specify periods=1
to only calculate the difference between adjacent rows. We then use .iloc[1]
to select the second row of the resulting DataFrame, which represents the difference between the first and second rows of the original DataFrame.
gistlibby LogSnag