You are looking for the axis parameter. Many Pandas functions accept this argument to apply a column or row operation. Use axis=0 for applying in different ways and axis=1 for applying in columns. This operation actually intersects the columns, so you want axis=1 .
df.cumsum(axis=1) by itself works on your example to create an output table.
In [3]: df.cumsum(axis=1) Out[3]: 1 2 3 4 10 16 30 41 61 51 13 29 40 50 13 11 30 45 61 321 12 27 37 52
I suspect you are interested in limiting a certain range of columns. For this you can use .loc with column labels (rows in the mine).
In [4]: df.loc[:, '2':'3'].cumsum(axis=1) Out[4]: 2 3 10 14 25 51 16 27 13 19 34 321 15 25
.loc is method-based and contains estimates. If you want to know more about indexing in Pandas, check out the docs .
Brian source share