Python Forum
Subtract rows (like r[1]-r[2] and r[3]-r[3]) and no pandas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Subtract rows (like r[1]-r[2] and r[3]-r[3]) and no pandas
#1
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
Reply
#2
What have you tried? We like to help people code, not code for people.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pandas Dataframe Filtering based on rows mvdlm 0 1,396 Apr-02-2022, 06:39 PM
Last Post: mvdlm
  [Pandas] Help with finding only non-matching rows LowEnd 3 3,450 Nov-12-2021, 02:34 PM
Last Post: jefsummers
  How to subtract columns with dates? jpy 3 2,219 Dec-29-2020, 12:11 AM
Last Post: jpy
  Fastest way to subtract elements of datasets of HDF5 file? Robotguy 3 2,585 Aug-01-2020, 11:48 PM
Last Post: scidam
  pandas head() not reading all rows naab 0 1,777 Apr-07-2020, 01:06 PM
Last Post: naab
  How to add a few empty rows into a pandas dataframe python_newbie09 2 16,280 Sep-20-2019, 08:52 AM
Last Post: python_newbie09
  Groupby in pandas with conditional - add and subtract rregorr 2 6,917 Jul-12-2019, 05:17 PM
Last Post: rregorr
  Write specific rows from pandas dataframe to csv file pradeepkumarbe 3 5,425 Oct-18-2018, 09:33 PM
Last Post: volcano63
  Output substrings from rows in pandas brocq_18 5 3,913 Jun-21-2018, 11:30 AM
Last Post: brocq_18
  pandas restricting csv read to certain rows metalray 5 20,753 Dec-16-2017, 07:39 AM
Last Post: metalray

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020