title: Add values to an external file in the form of columns
body: <p>I would like to know how I can put the values ​​resulting from my loops into the external file in form of columns. I have this code:</p>
  
  <p>Perhaps a very specific brief explanation of what I would like to obtain could help me a bit, I have a group of particles that fall on the surface of the earth around a point (0.0) each with their respective weights and I would like to know the sum of the weights of the particles that fall within the rings of internal radius Ri and external Rj (the external radius of the first ring becomes the internal radius of the ring that follows it)</p>
  
  <pre><code> #Insert the radio values
   #For example Ri_0=-20
   #For example Rj_max=4000
   #For example Bin=40
  
   data=pd.read_csv("photons.txt", header=0, delim_whitespace=True)
  
   df=pd.DataFrame(data)`
  
   Ri_0=input("Insert the internal minimum radius value: ") 
  
   Rj_max=input("Insert the external maximum radius value: ") 
  
   Bin= input("Insert the bin: ")     
  
   R_internals=range(Ri_0,Rj_max+1,Bin)
   Ri=list(R_internals)
   Rj=[]
   R=[]
  
   for m in Ri:
       R_externals=m+Bin
       Rj.append(R_externals)
  
   for d,f in zip(Ri,Rj):
       R_average=(d+f)/2
       R.append(R_average) 
  
   import zipfile
  
   #Loops
   count=0
  
  
   #I think the problem is in this loop
  
   for i,j in zip(Ri,Rj):
       for r in df["radio"]:
           if r &gt;= i and r &lt;= j:
               d=df[df['radio']==r]['ParWeight'].iloc[0]
               count=count+d
  </code></pre>
  
  <p>I have a problem adding the sum of the weights of the particles that fall within the internal radius ring Ri and external Rj and then adding it to an external file in the form of a data column and next to it the value of R that comes to be the average of Ri and Rj, I get a systematic error because it adds the value of the sum of weights of all the particles and does not separate them by ring, I attach the file "photons.txt" in the next link [<a href="https://drive.google.com/file/d/1YM0U3UN4p1OGvbiajZakMWtQSmyZoCkN/view?usp=sharing]" rel="nofollow noreferrer">https://drive.google.com/file/d/1YM0U3UN4p1OGvbiajZakMWtQSmyZoCkN/view?usp=sharing]</a></p>
  
  <p>I was several days to trying to solve that problem.
  Thanks so much.</p>