Python Forum

Full Version: Subtract rows (like r[1]-r[2] and r[3]-r[3]) and no pandas
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have csv file like below

Account Dates Sales
ADBVC 10-dec-2018 12
ADBVC 11-Dec-2018 10
SDFC 14-Dec-2018 15
SDFC 10-Dec-2018 11

I want output like

Account Dates Sales Avg
ADBVC 10-dec-2018 12 Nan (because 12 - null)
ADBVC 11-Dec-2018 10 10-12 =2 (Here I have to subtract row2 - row1)
SDFC 14-Dec-2018 15 NaN(15-Null)
SDFC 10-Dec-2018 11 11-15 =14(Here I have to subtract row4 - row3 and so on...)

I read it can be done easily in pandas, but I trying to do in a pure python way!! Thanks
What have you tried? We like to help people code, not code for people.