I have a pandas dataframe of format with 226 columns :

```
**W    X    Y    Z.....**
  a    b    c    d.....
  e    f    g    h.....    

```

i want to subtract columns Y and Z in the following way:

```
**W      X      Y          Z.....**
  a    (b-c)  (c-d)  (d-nextvalue).....
  e    (f-g)  (g-h)  (h-nextvalue).....   

```

how do i go about doing this? I am a rookie in python, thanks in advance
['https://Stackoverflow.com/questions/59835541', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12724372/']
Use [`DataFrame.diff`](http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.diff.html) and if necessary convert first column to index by [`DataFrame.set_index`](http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.set_index.html):

```
df = pd.DataFrame({
        'W':list('abc'),
         'X':[10,5,4],
         'Y':[7,8,9],
         'Z':[1,1,0],
         'E':[5,3,6],
})

df = df.set_index('W').diff(-1, axis=1)
print (df)
      X    Y    Z   E
W                   
a  3.0  6.0 -4.0 NaN
b -3.0  7.0 -2.0 NaN
c -5.0  9.0 -6.0 NaN

```
To create 'W' as the index you can do,

```
df.set_index('W', inplace=True)

```

Further, you may try the following:

```
for i in range(len(df.columns) - 1):
    df.iloc[:, i] = df.iloc[:, i] - df.iloc[:, i+1]

```