Bottom Page

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
Quote
#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

Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  pandas head() not reading all rows naab 0 199 Apr-07-2020, 01:06 PM
Last Post: naab
  How to add a few empty rows into a pandas dataframe python_newbie09 2 4,230 Sep-20-2019, 08:52 AM
Last Post: python_newbie09
  Groupby in pandas with conditional - add and subtract rregorr 2 2,731 Jul-12-2019, 05:17 PM
Last Post: rregorr
  Write specific rows from pandas dataframe to csv file pradeepkumarbe 3 1,434 Oct-18-2018, 09:33 PM
Last Post: volcano63
  Output substrings from rows in pandas brocq_18 5 992 Jun-21-2018, 11:30 AM
Last Post: brocq_18
  pandas restricting csv read to certain rows metalray 5 15,569 Dec-16-2017, 07:39 AM
Last Post: metalray

Forum Jump:


Users browsing this thread: 1 Guest(s)