title: Regarding getting the rowsum of a python data frame
body: <p>I have following python data frame</p>
  
  <pre><code>data={'1':[1,1,1,1],'2':[1,1,1,1],'3':[1,1,1,1]}
  df=pd.DataFrame(data)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/DLfpd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DLfpd.png" alt="enter image description here"></a></p>
  
  <p>I need to get the <strong>sum of the rows</strong> in a such away that my <strong>final output should be like this,</strong></p>
  
  <p><a href="https://i.stack.imgur.com/4tSvJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4tSvJ.png" alt="enter image description here"></a></p>
  
  <p>So in this desired output, the second column should contain the row sum up to second column of the original data frame. So on. </p>
  
  <p>To get this output, I wrote the following code,</p>
  
  <pre><code>sum_mat=np.zeros(shape=(3,3))
  
  numOfIteration=3
  itr=list(range(0,numOfIteration))
  
  for i in range(0,3):
      for j in range(0,3):
          while i &lt;= itr[i]:
              sum_mat[i,j]+= df.iloc[i,j]
  
  print (sum_mat)
  </code></pre>
  
  <p>I am not getting an output here because the code is running forever (may be an infinite loop). </p>
  
  <p>Can anyone suggest anything to get the desired output ?</p>
  
  <p>May be there is more effective and easier way to do the same thing.</p>
  
  <p>Thank you</p>
  
  <p><strong>UPDATE:</strong>
  i update the for loop as follows,</p>
  
  <pre><code>for i in range(0,3):
     for j in range(0,3):
          while i &lt;= itr[i]:
             sum_mat[i,j] = df.iloc[:,0:i].sum(axis=1)
  </code></pre>
  
  <p>but it gives following error,</p>
  
  <pre><code>sum_mat[i,j] = df.iloc[:,0:i].sum(axis=1)
  ValueError: setting an array element with a sequence.
  </code></pre>