Python Forum
subtruction of columns in pandas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
subtruction of columns in pandas
#4
How about

sum(df[next_col] - df[curr_col] for curr_col, next_col in zip(df.columns, df.columns[1:]))
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Messages In This Thread
subtruction of columns in pandas - by garikhgh0 - May-11-2018, 09:30 AM
RE: subtruction of columns in pandas - by scidam - May-12-2018, 02:48 AM
RE: subtruction of columns in pandas - by garikhgh0 - May-14-2018, 05:31 AM
RE: subtruction of columns in pandas - by volcano63 - May-14-2018, 10:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  iretate over columns in df and calculate euclidean distance with one column in pandas Pit292 0 3,314 May-09-2021, 06:46 PM
Last Post: Pit292
  pandas.to_datetime: Combine data from 2 columns ju21878436312 1 2,463 Feb-20-2021, 08:25 PM
Last Post: perfringo
  Remove extra count columns created by pandas groupby spyf8 1 2,741 Feb-10-2021, 09:19 AM
Last Post: Naheed
  Pandas: summing columns conditional on the column labels ddd2332 0 2,146 Sep-10-2020, 05:58 PM
Last Post: ddd2332
  Difference of two columns in Pandas dataframe zinho 2 3,383 Jun-17-2020, 03:36 PM
Last Post: zinho
  Pandas dataframe columns collapsed in Spyder when printing UniKlixX 2 4,764 Nov-04-2019, 07:00 AM
Last Post: UniKlixX
  [pandas] How to re-arrange DataFrame columns SriMekala 8 4,966 Jun-22-2019, 12:55 AM
Last Post: scidam
  Pandas - cumulative sum of two columns tobbs 12 8,806 May-25-2019, 08:37 PM
Last Post: tobbs
  comparing two columns two different files in pandas nuncio 0 2,413 Jun-06-2018, 01:04 PM
Last Post: nuncio

Forum Jump:

User Panel Messages

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